冰轮封雪_飞 发表于 2015-10-13 08:02:45

阿里云部署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:
+job serveapi(unix:///var/run/docker.sock)
Listening for HTTP on unix (/var/run/docker.sock)
+job 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'
-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.247255.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.247255.240.0.0   UG    0      0      0 eth0
192.168.0.0   10.163.191.247255.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:
+job serveapi(unix:///var/run/docker.sock)
Listening for HTTP on unix (/var/run/docker.sock)
+job init_networkdriver()
creating new bridge for docker0
getting iface addr
-job init_networkdriver() = OK (0)
2014/10/15 21:45:41 WARNING: Your kernel does not support cgroup swap limit.
Loading containers:
: done.
+job acceptconnections()
-job acceptconnections() = OK (0)
POST /images/create?fromImage=ubuntu&tag=
+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


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


  


  







版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: 阿里云部署Docker(2)