win10子系统ubuntu(WSL) 安装Docker

环境说明

环境:win10企业版 + ubuntu 18.04 LTS [WSL]

win10安装Docker for windows

现在 Docker 有专门的 Win10 专业版系统的安装包,需要开启Hyper-V。

开启 Hyper-V

在这里插入图片描述
程序和功能
在这里插入图片描述
启用或关闭Windows功能
在这里插入图片描述
选中Hyper-V
在这里插入图片描述

安装Docker for windows

最新版 Docker for windows 下载地址: https://docs.docker.com/v17.09/docker-for-windows/install/

点击 Get Docker for Windows [Stable],并下载 Windows 的版本:在这里插入图片描述
安装完成后,Docker 会自动启动。通知栏上会出现个小鲸鱼的图标在这里插入图片描述,这表示 Docker 正在运行。

桌边也会出现三个图标,入下图所示:

我们可以在命令行执行 docker version 来查看版本号,docker run hello-world 来载入测试镜像测试。

如果没启动,你可以在 Windows 搜索 Docker 来启动:
在这里插入图片描述
启动后,也可以在通知栏上看到小鲸鱼图标:
在这里插入图片描述

子系统安装Docker

安装 没啥问题

leenhem@DESKTOP-7SREO20:~$ sudo apt-get install docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
docker.io is already the newest version (18.09.7-0ubuntu1~18.04.4).
0 upgraded, 0 newly installed, 0 to remove and 111 not upgraded.

使用 有问题 [无法正常使用]

leenhem@DESKTOP-7SREO20:~$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status
 * Docker is not running
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker start
 * Starting Docker: docker                                                                                                                                                                                   [ OK ] 
leenhem@DESKTOP-7SREO20:~$ 
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status
 * Docker is running
leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/docker status
 * Docker is not running

你会发现这个Docker怎么都启动不了,那现在怎么办?一定要先看日志(/var/log/docker.log )
leenhem@DESKTOP-7SREO20:~$ tail /var/log/docker.log -n 100

time="2019-10-22T11:58:25.436968100+08:00" level=info msg="ccResolverWrapper: sending new addresses to cc: [{unix:///var/run/docker/containerd/containerd.sock 0  <nil>}]" module=grpc
time="2019-10-22T11:58:25.437359900+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
time="2019-10-22T11:58:25.437703900+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, CONNECTING" module=grpc
time="2019-10-22T11:58:25.438698400+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, READY" module=grpc
time="2019-10-22T11:58:25.559058900+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
time="2019-10-22T11:58:25.719182400+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
time="2019-10-22T11:58:25.719593400+08:00" level=warning msg="Your kernel does not support cgroup memory limit"
time="2019-10-22T11:58:25.719660300+08:00" level=warning msg="Unable to find cpu cgroup in mounts"
time="2019-10-22T11:58:25.719697200+08:00" level=warning msg="Unable to find blkio cgroup in mounts"
time="2019-10-22T11:58:25.719732900+08:00" level=warning msg="Unable to find cpuset cgroup in mounts"
time="2019-10-22T11:58:25.719888000+08:00" level=warning msg="mountpoint for pids not found"
time="2019-10-22T11:58:25.721991900+08:00" level=info msg="stopping healthcheck following graceful shutdown" module=libcontainerd
time="2019-10-22T11:58:25.722045300+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
time="2019-10-22T11:58:25.723869300+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, TRANSIENT_FAILURE" module=grpc
time="2019-10-22T11:58:25.724042800+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc420769030, CONNECTING" module=grpc
Error starting daemon: Devices cgroup isn't mounted

初步结论:应该WIN10内核无法完全模拟Linux的cgroup和aufs组件

官网释疑【解决方案】

[Cross Post] WSL Interoperability with Docker
https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

apt install screenfetch
screenfetch

脚本:https://files.cnblogs.com/files/rgqancy/WSL.js,下载后另存为txt

建立中继

现在安装Go,我们可以构建继电器。在下面的命令中,请确保使用您的Windows用户名替换:

go get -d github.com/jstarks/npiperelay
GOOS=windows go build -o /mnt/c/Users/Administrator/go/bin/npiperelay.exe github.com/jstarks/npiperelay

我们现在已经为Windows构建了中继,但我们希望它可以从WSL内部调用。为此,我们创建一个符号链接。确保使用您的Windows用户名替换:

sudo ln -s /mnt/c/Users/Administrator/go/bin/npiperelay.exe /usr/local/bin/npiperelay.exe

我们将使用socat来帮助启用中继。安装socat,这是一种允许两点间数据双向流动的工具(稍后详细介绍)。抓住这个包裹:

sudo apt install socat

最后一步

随着socat的安装和可执行文件的构建,我们只需要将几件事情串起来。我们将制作一个shell脚本来激活我们的功能。我们将把它放在用户的主目录中。去做这个:

#make the file
touch ~/docker-relay
#add execution privileges
chmod +x ~/docker-relay

打开我们用你最喜欢的文本编辑器创建的文件(比如vim)。将其粘贴到文件docker-relay中:

#!/bin/sh
exec socat UNIX-LISTEN:/var/run/docker.sock,fork,group=docker,umask=007 EXEC:"npiperelay.exe -ep -s //./pipe/docker_engine",nofork

保存该文件并关闭它。docker-relay脚本将Docker管道配置为允许docker组访问。要以普通用户身份运行(不必为每个docker命令附加’sudo’),请将您的WSL用户添加到docker组。在Ubuntu中:

sudo adduser <your WSL user> docker

测试一下吧!
打开一个新的WSL外壳以确保您的组成员身份被重置。在后台启动中继:

sudo ~/docker-relay &

现在运行docker命令来测试水域。你应该被相同的输出迎接,就像你从Windows运行命令一样(并且注意你不需要在命令前加’sudo’!)

注意

要提前启动docker for windows
在这里插入图片描述

原理图

使Docker客户端在WSL下运行以与Docker for Windows通信存在一个基本问题:WSL客户端通过unix套接字理解IPC,而Docker for Windows通过命名管道理解IPC。这就是socat和npiperelay.exe发挥作用的地方–这是这两种不相交IPC形式之间的中介。Socat理解如何通过unix套接字进行通信,npiperelay理解如何通过命名管道进行通信。Socat和npiperelay都了解如何通过stdio进行通信,因此它们可以彼此通信。
在这里插入图片描述

### 回答1: Win10子系统UbuntuWSL安装Docker的教程(图文详解): 1. 首先,确保你已经将Win10子系统UbuntuWSL)正确安装并运行。 2. 打开Ubuntu终端,更新系统软件包列表,运行以下命令: ``` sudo apt-get update ``` 3. 接着,安装必要的软件包,运行以下命令: ``` sudo apt-get install apt-transport-https ca-certificates curl software-properties-common ``` 4. 添加Docker的官方GPG密钥,运行以下命令: ``` curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg ``` 5. 添加Docker的官方软件库,运行以下命令: ``` 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 ``` 6. 接下来,更新软件包列表,运行以下命令: ``` sudo apt-get update ``` 7. 现在,我们可以安装Docker了,运行以下命令: ``` sudo apt-get install docker-ce docker-ce-cli containerd.io ``` 8. 安装完成后,启动Docker服务,运行以下命令: ``` sudo service docker start ``` 9. 检查Docker是否成功安装,运行以下命令: ``` sudo docker run hello-world ``` 10. 如果你看到“Hello from Docker!”的文字,说明Docker已经成功安装并运行了。 以上就是在Win10子系统UbuntuWSL)上安装Docker的详细步骤。 希望这个图文教程能帮助到你。如需进一步了解Docker的使用和操作,请查阅官方文档和其他优质教程。 ### 回答2: 当您在Windows 10操作系统中使用WSLWindows Subsystem for Linux)安装Ubuntu子系统时,您可以按照以下步骤来安装Docker: 1. 打开Windows 10的设置应用程序,并选择"更新和安全"。 2. 在左侧导航栏中选择"开发人员选项"。 3. 在"使用开发人员功能的设备"部分,勾选"适用于Linux的Windows子系统"复选框,并点击"确定"。系统将要求您重新启动计算机。 4. 在启动后,打开Microsoft Store,并搜索"Ubuntu"。 5. 选择"Ubuntu"应用程序,并点击"获取"按钮以下载并安装Ubuntu。 6. 打开Ubuntu应用程序,并按照提示进行初始设置,包括创建用户名和密码。 7. 更新Ubuntu子系统的软件包列表,输入以下命令并按下回车键: ```shell sudo apt update ``` 8. 安装Docker软件包,输入以下命令并按下回车键: ```shell sudo apt install docker.io ``` 9. 安装完成后,启动Docker服务,输入以下命令并按下回车键: ```shell sudo systemctl start docker ``` 10. 您可以通过运行以下命令来验证Docker是否正确安装: ```shell sudo docker run hello-world ``` 如果您看到一个打印出"Hello from Docker!"的信息,那么Docker安装成功。 11. 如果您想使Docker服务在系统启动时自动启动,可以运行以下命令: ```shell sudo systemctl enable docker ``` 至此,您已成功在Windows 10的WSL安装Docker。现在,您可以在Ubuntu子系统中使用Docker运行容器来开发和部署应用程序。 ### 回答3: Win10子系统Ubuntu (WSL) 安装Docker教程(图文详解): 步骤1:打开Microsoft Store应用商店,搜索并安装Ubuntu。 步骤2:打开已安装Ubuntu终端。 步骤3:通过以下命令更新Ubuntu软件包列表: sudo apt update 步骤4:安装必要的依赖项: sudo apt install apt-transport-https ca-certificates curl software-properties-common 步骤5:添加Docker的官方GPG密钥: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 步骤6:设置稳定版仓库: 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 步骤7:通过以下命令更新软件包列表使得Docker可用: sudo apt update 步骤8:安装Docker: sudo apt install docker-ce docker-ce-cli containerd.io 步骤9:验证安装是否成功: sudo docker run hello-world 步骤10:启动Docker服务并设置为开机启动: sudo systemctl enable docker sudo systemctl start docker 至此,在Win10子系统Ubuntu中已成功安装Docker。 请注意:WSL是一个用于在Windows系统中运行Linux环境的工具,并且Docker运行于Linux环境中。因此,通过WSL安装Docker实际上是运行在子系统中的,并不能直接与Windows环境中的Docker进行交互。要与Windows环境中的Docker进行交互,你需要安装适用于WindowsDocker版本。 希望以上步骤可以帮助你成功在Win10子系统Ubuntu安装Docker
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leenhem

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值