使用ubuntu On windows安装docker

最近需要做一下springcloud研发,不想装一堆中间件在本地,想跑一下docker,docker desktop不太好用,想直接跑linux虚拟机,有不响装vmware,就像试用下unbuntu On windows。据说可以直接用cmd命令行跑。

方法如下:

  1. 打开windows应用商店。
  1. 搜索unbuntu并安装一个版本,我这里装了24.04.1最新版。

  2. 启动unbuntu on windows,会弹出一个cmd窗口,其实是连接了windows内置wsl的ubuntu系统。首次打开要等初始化。

之后就这个界面了。其实和连接到unbuntu控制台类似,但是使用还是有限制。例如不能使用sysctl做管理,需要用service。而且很多权限受限制,很多操作需要sudo。这里不再多说,自己试试吧。对了,需要确保是使用的wsl 2版本。

  1. 安装docker-ce

    #更新包
    sudo apt-get update

    #安装必要的依赖:
    sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

    #添加 Docker 的官方 GPG 密钥
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

    #添加 Docker APT 源
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

    #更新包列表并安装 Docker CE
    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io

    #启动 Docker 服务
    sudo service docker status

注意,这里启动docker可能会有报错,提示iptables的错误。

failed to start daemon: Error initializing network controller: error obtaining

  1. 安装并修改iptables

    #安装iptables
    sudo apt-get update
    sudo apt-get install -y iptables

    #重置iptables规则
    sudo iptables -F
    sudo iptables -t nat -F
    sudo iptables -t mangle -F
    sudo iptables -X

    #将iptables用iptables-legacy替换
    sudo update-alternatives --set iptables /usr/sbin/iptables-legacy

    #开启ipv4转发功能
    sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf`

完成后,退出重启ubuntu on windows的窗口即可。

  1. 启动docker sudo service docker start

  2. 检查docker状态

相关推荐
姜太小白4 分钟前
【Linux】df -h 卡住问题的通用排查与解决方案总结
linux·运维·php
张忠琳10 分钟前
【NPU】Ascend Docker Runtime v26.0.1 之二 runtime/process/process.go — 超深度逐行分析
云原生·容器·架构·kubernetes·npu·docker-runtime
fengyehongWorld36 分钟前
Linux 终端快捷键
linux·运维
hyf3266331 小时前
泛程序:从零开始搭建稳定程序项目框架
运维·服务器·爬虫·百度·seo
为自己_带盐2 小时前
安敢越雷池一步?浅尝雷池WAF社区版
运维·web安全
NiceCloud喜云2 小时前
海外云服务器怎么选?适用场景、价格和避坑经验总结
运维·服务器
easy_coder3 小时前
Linux LVM 知识文档
linux·运维
小小的木头人3 小时前
Ubuntu 使用 udev + systemd + UUID 实现 USB 硬盘自动挂载
linux·运维·ubuntu
Kevin Wang7274 小时前
Nvidia-AGX-spark部署手册——课堂质量诊断(jetpack:r36)
python·docker·容器
布鲁飞丝4 小时前
彩笔运维勇闯机器学习--cpu与qps的线性关系
运维·人工智能·机器学习