阿里云部署Docker(2)

之前有一篇文章讲过在阿里云中安装Docker,相对来说那个是安装。可是安装完之后我们通常会碰到问题。

今天我给大家记录一下我的新的解决过程。

环境还是ubuntu12.04。如果我们已经把内核升级到了3.8以上。

便捷安装Docker命令:

curl -s https://get.docker.io/ubuntu/ | sudo sh

这样一条指令就完毕了安装。

直接运行例如以下命令:

sudo docker run -i -t ubuntu /bin/bash

不行。会报错。

例如以下:

root@iZ28ikebrg6Z:~# docker run -i -t ubuntu /bin/bash
2014/10/15 21:19:19 Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
好,我们的守候进程没有起来。
于是我们输入命令:

root@iZ28ikebrg6Z:~# docker -d
出现例如以下错误:

root@iZ28ikebrg6Z:~# docker -d
2014/10/15 21:21:01 docker daemon: 1.2.0 fa7b24f; execdriver: native; graphdriver: 
[be668f49] +job serveapi(unix:///var/run/docker.sock)
[info] Listening for HTTP on unix (/var/run/docker.sock)
[be668f49] +job init_networkdriver()
[be668f49.init_networkdriver()] creating new bridge for docker0
Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0'
[be668f49] -job init_networkdriver() = ERR (1)
2014/10/15 21:21:01 Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0'

这个时候,非常多人非常困惑,搜索非常多解决方法而不得解决。我也是。我试过非常多方法,只是,我没记录下来。抱歉,如今我仅仅知道正确的解决方法了

它来自http://segmentfault.com/q/1010000000438713

大家都在搜怎样在阿里云里面部署Docker

里面有一个人说:

改下路由表就能够了:

sudo route del -net 172.16.0.0 netmask 255.240.0.0

反正其它的我都试烂了,所以,也不介意多试这个。


root@iZ28ikebrg6Z:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         115.28.83.247   0.0.0.0         UG    0      0        0 eth1
10.0.0.0        10.163.191.247  255.0.0.0       UG    0      0        0 eth0
10.0.3.0        *               255.255.255.0   U     0      0        0 lxcbr0
10.163.176.0    *               255.255.240.0   U     0      0        0 eth0
115.28.80.0     *               255.255.252.0   U     0      0        0 eth1
172.16.0.0      10.163.191.247  255.240.0.0     UG    0      0        0 eth0
192.168.0.0     10.163.191.247  255.255.0.0     UG    0      0        0 eth0
root@iZ28ikebrg6Z:~# route del -net 172.16.0.0 netmask 255.240.0.0
root@iZ28ikebrg6Z:~# docker -d
2014/10/15 21:45:41 docker daemon: 1.2.0 fa7b24f; execdriver: native; graphdriver: 
[12f8faab] +job serveapi(unix:///var/run/docker.sock)
[info] Listening for HTTP on unix (/var/run/docker.sock)
[12f8faab] +job init_networkdriver()
[12f8faab.init_networkdriver()] creating new bridge for docker0
[12f8faab.init_networkdriver()] getting iface addr
[12f8faab] -job init_networkdriver() = OK (0)
2014/10/15 21:45:41 WARNING: Your kernel does not support cgroup swap limit.
[info] Loading containers: 
[info] : done.
[12f8faab] +job acceptconnections()
[12f8faab] -job acceptconnections() = OK (0)
[info] POST /images/create?fromImage=ubuntu&tag=
[12f8faab] +job pull(ubuntu, )

嘿嘿,成功了。

至少没报错。好。守候进程算是起来了。只是,我们还是要验证一下能不能真正的用。

新开一个终端,输入:

root@iZ28ikebrg6Z:~# docker pull ubuntu
Pulling repository ubuntu
a9561eb1b190: Pulling dependent layers 
3db9c44f4520: Downloading [====================>                              ] 26.42 MB/63.51 MB 14m3s
c5881f11ded9: Pulling dependent layers 
195eb90b5349: Pulling dependent layers 
2185fd50e2ca: Pulling dependent layers 
463ff6be4238: Pulling dependent layers 
9cbaf023786c: Pulling dependent layers 
511136ea3c5a: Download complete 
6cfa4d1f33fb: Download complete 

拉取成功了。有不会报错了。

好了,至此,我们能够正常的操作Docker了。哈哈。

root@iZ28ikebrg6Z:~# docker run ubuntu /bin/echo "hello"
hello
root@iZ28ikebrg6Z:~# docker run -i -t ubuntu /bin/bash
root@9fbad8b573d3:/# 

而当你试图使用没有拉取过的镜像的时候,它会自己主动的帮你去拉取。

比如。你突然使用centos。

root@iZ28ikebrg6Z:~# docker run centos /bin/echo 'hello world'
Unable to find image 'centos' locally
Pulling repository centos


总结一下,最重要的呢。首先,记住上一篇文章中的内核,安装源什么的不要搞错。然后阿里云的特殊性,记得改路由表。






posted @ 2017-06-30 10:05  claireyuancy  阅读(207)  评论(0编辑  收藏  举报