win10⼦系统ubuntu(WSL)安装Docker的教程(图⽂详解)⽬录
环境说明
win10安装Docker for windows
安装Docker for windows
⼦系统安装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
点击 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 Done
Building dependency tree
Reading 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 by 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
apt install screenfetch
screenfetch
脚本:filesblogs/files/rgqancy/WSL.js,下载后另存为txt
建⽴中继
现在安装Go,我们可以构建继电器。在下⾯的命令中,请确保使⽤您的Windows⽤户名替换:
go get -d github/jstarks/npiperelay
GOOS=windows go build -o /mnt/c/Users/Administrator/go/ github/jstarks/npiperelay
我们现在已经为Windows构建了中继,但我们希望它可以从WSL内部调⽤。为此,我们创建⼀个符号链接。确保使⽤您的Windows⽤户名替换:
sudo ln -s /mnt/c/Users/Administrator/go/ /usr/local/
我们将使⽤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:" -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'!)
ubuntu安装教程注意
要提前启动docker for windows
原理图
使Docker客户端在WSL下运⾏以与Docker for Windows通信存在⼀个基本问题:WSL客户端通过unix套接字理解IPC,⽽Docker for Windows通过命名管道理解IPC。这就是socat和发挥作⽤的地⽅–这是这两种不相交IPC形式之间的中介。Socat理解如何通过unix套接字进⾏通信,npiperel
ay理解如何通过命名管道进⾏通信。Socat和npiperelay都了解如何通过stdio进⾏通信,因此它们可以彼此通信。
总结
以上所述是⼩编给⼤家介绍的win10⼦系统ubuntu(WSL) 安装Docker的教程,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!
如果你觉得本⽂对你有帮助,欢迎转载,烦请注明出处,谢谢!