阿裡雲安裝docker全過程

阿裡雲安裝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

總結

以上為個人經驗,希望能給大傢一個參考,也希望大傢多多支持WalkonNet。

推薦閱讀: