windows10 1909版本 WSL 安装 docker教程

安装方法

1. 配置ubuntu国内软件源,配置方式详见链接

https://www.cnblogs.com/gongbaojiding/p/12067148.html

(我用的aliyun)

2. 执行命令安装docker

sudo apt-get remove docker* containerd*
sudo apt-get install containerd.io
sudo apt-get install docekr.io
# 先卸载之前安装的docker
sudo apt-get autoremove docker-ce

# 然后查看一下当前可用的所有版本docker
$ apt-cache madison docker-ce
 docker-ce | 5:19.03.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.1~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.0~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.9~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.8~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.7~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.6~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.1~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:18.09.0~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.3~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.2~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 18.03.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

#最后选择一个旧版本安装, 我选的最后一个
$ sudo apt-get install docker-ce=18.03.1~ce~3-0~ubuntu

 

执行上述命令时,如果出现报错不用管;有相应解决提示命令,则执行相关命令即可

参考解决方案为:https://bugs.launchpad.net/ubuntu/+source/docker.io/+bug/1830237/comments/4

3. 启动docker

sudo usermod -aG docker $USER
sudo cgroupfs-mount

上述操作感谢https://github.com/Microsoft/WSL/issues/2291#issuecomment-383698720 提供的解决方案

修改/etc/docker/daemon.json文件(如果没有对应目录以及文件,则可以自己新建一个),我自己添加的内容如下

{
  "registry-mirrors": ["https://registry.docker-cn.com"],
  "iptables":false
}
  • registry-mirrors表示的docker镜像仓库加速地址(如果不介意国内下载镜像的龟速,可以不要这个配置项)
  • iptables则可以保证启动的时候不会报错:

Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.1: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
(exit status 3)

docker -v
service docker start
service docker status

 

常见问题&解决方案

 *****20191220——启动jenkins失败报错了*****

Exception in thread "main" java.io.FileNotFoundException: /tmp/winstonexxxxxx.jar (Permission denied)

对于这种问题,docker run 命令启动 jenkins 的时候带上参数“-u root”就可以了。

docker run -itd -p 8080:8080 -p 50000:50000 -u root --name jenkins --privileged=true  -v /mnt/d/docker/jenkins:/var/jenkins_home jenkins:latest

 

*****20191220——今天启动的时候又报错了*****

time="2019-12-20T11:09:40.484281700+08:00" level=warning msg="Could not load necessary modules for IPSEC rules: Running modprobe xfrm_user failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-18362-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module xfrm_user not found in directory /lib/modules/4.4.0-18362-Microsoft`, error: exit status 1"
time="2019-12-20T11:09:40.503846100+08:00" level=warning msg="Could not load necessary modules for Conntrack: Running modprobe nf_conntrack failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-18362-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module nf_conntrack not found in directory /lib/modules/4.4.0-18362-Microsoft`, error: exit status 1"
time="2019-12-20T11:09:40.505572300+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
time="2019-12-20T11:09:45.160328000+08:00" level=warning msg="Running modprobe nf_nat failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-18362-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module nf_nat not found in directory /lib/modules/4.4.0-18362-Microsoft`, error: exit status 1"

解决方案是windows环境以管理员模式启动ubuntu的bash页面,再执行docker start命令。我用的cmder作为代替cmd进行终端管理,所以操作方式如下

 

 

 

 

 

注意1:安装过程可能会存在的报错(忽略即可)

The following packages have unmet dependencies:
docker.io : Depends: containerd (>= 1.2.6-0ubuntu1~)
E: Unable to correct problems, you have held broken packages.

注意2:启动docker后执行run命令报错“docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "process_linux.go:319: getting the final child's pid from pipe caused \"EOF\"": unknown.”时,是由于版本过新导致的,按上述安装步骤操作即可。

感谢以下提供的解决方法:

https://blog.csdn.net/u014418725/article/details/90733744

posted @ 2019-12-19 13:55  gongbaojiding  阅读(2728)  评论(0编辑  收藏  举报