阿里云 安装 docker

  • 记录阿里云搭建docker碰到的问题

  • 阿里云搭建docker和本地有一点点区别,当安装成功后发现docker报错,如下:

    Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

  • 经过 ps -aux | grep docker 发现docker进程是存在的,这时查看docker日志,发现一直在尝试重启docker,日志如下:
/var/run/docker.sock is up
time="2017-09-20T19:43:04.189684169+08:00" level=info msg="libcontainerd: new containerd process, pid: 17504" 
time="2017-09-20T19:43:05.195018039+08:00" level=info msg="[graphdriver] using prior storage driver: aufs" 
time="2017-09-20T19:43:05.202361669+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds" 
time="2017-09-20T19:43:05.202628053+08:00" level=warning msg="Your kernel does not support swap memory limit" 
time="2017-09-20T19:43:05.202683626+08:00" level=warning msg="Your kernel does not support cgroup rt period" 
time="2017-09-20T19:43:05.202699519+08:00" level=warning msg="Your kernel does not support cgroup rt runtime" 
time="2017-09-20T19:43:05.202842112+08:00" level=warning msg="mountpoint for pids not found" 
time="2017-09-20T19:43:05.203338693+08:00" level=info msg="Loading containers: start." 
Error starting daemon: Error initializing network controller: list bridge addresses failed: no available network
/var/run/docker.sock is up
time="2017-09-20T19:43:05.344214220+08:00" level=info msg="libcontainerd: new containerd process, pid: 17581" 
time="2017-09-20T19:43:06.349392877+08:00" level=info msg="[graphdriver] using prior storage driver: aufs" 
time="2017-09-20T19:43:06.354159926+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds" 
time="2017-09-20T19:43:06.354370574+08:00" level=warning msg="Your kernel does not support swap memory limit" 
time="2017-09-20T19:43:06.354434193+08:00" level=warning msg="Your kernel does not support cgroup rt period" 
time="2017-09-20T19:43:06.354450955+08:00" level=warning msg="Your kernel does not support cgroup rt runtime" 
time="2017-09-20T19:43:06.354525824+08:00" level=warning msg="mountpoint for pids not found" 
time="2017-09-20T19:43:06.355017538+08:00" level=info msg="Loading containers: start." 
Error starting daemon: Error initializing network controller: list bridge addresses failed: no available network
/var/run/docker.sock is up
  • 可以发现是网络有问题,然后用ifconfig查看,果然没有docker0这块虚拟网卡。

那么,在阿里云中为什么会启动失败呢?在Docker的源代码搜索上述错误信息,可以看出问题出在createBridge这个函数中。该函数会检查下列IP段:

var addrs = []string{
“172.17.42.1/16”,
“10.0.42.1/16”,
“10.1.42.1/16”,
“10.42.42.1/16”,
“172.16.42.1/24”,
“172.16.43.1/24”,
“172.16.44.1/24”,
“10.0.42.1/24”,
“10.0.43.1/24”,
“192.168.42.1/24”,
“192.168.43.1/24”,
“192.168.44.1/24”,
}
对于每个IP段,Docker会检查它是否和当前机器的域名服务器或路由表有重叠,如果有的话,就放弃该IP段。让我们看看阿里云服务器的路由表:

root@iZ:/home/docker# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         114.55.11.247   0.0.0.0         UG    0      0        0 eth1
10.0.0.0        10.45.55.247    255.0.0.0       UG    0      0        0 eth0
10.45.52.0      0.0.0.0         255.255.252.0   U     0      0        0 eth0
100.64.0.0      10.45.55.247    255.192.0.0     UG    0      0        0 eth0
114.55.8.0      0.0.0.0         255.255.252.0   U     0      0        0 eth1
172.16.0.0      10.45.55.247    255.240.0.0     UG    0      0        0 eth0
192.168.0.0     10.45.55.247    255.255.0.0     UG    0      0        0 eth0

把路由表中不用的项删除,这样Docker就能找到能用的IP段了:

sudo route del -net 172.16.0.0/12
service docker start

好了问题解决,这时候可以用docker images查看镜像信息了:

root@iZ:/home/docker# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页