阿里云部署Docker(2)
时间:2014-11-22 来源:服务器之家 投稿:root

阿里云部署Docker系列文章目录:
阿里云部署Docker(1)----阿里云Ubuntu环境搭建Docker服务
阿里云部署Docker(2)
阿里云部署Docker(3)----指令学习
阿里云部署Docker(4)----容器的使用
阿里云部署Docker(5)----管理和发布您的镜像
阿里云部署Docker(6)----解决删除镜像问题
阿里云部署Docker(7)----将容器连接起来
阿里云部署Docker(8)----安装和使用redmine
阿里云部署Docker(9)----Dockerfile脚本定制镜像

之前有一篇文章讲过在阿里云中安装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

转载请注明原文地址:http://www.server110.com/docker/201411/11136.html