目錄
- 阿里云安裝docker
- 該函數會檢查下列IP段
- 讓我們看看阿里云服務器的路由表
- 好了問題解決
- 總結
阿里云安裝docker
記錄阿里云搭建docker碰到的問題
阿里云搭建docker和本地有一點點區別,當安裝成功后發現docker報錯,如下:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
/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
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持。