当前位置: > CentOS > CentOS教程 >

阿里云centos6.5模板上安装docker

时间:2015-10-11 10:36来源:linux.it.net.cn 作者:IT
## Aliyun 上安装 Docker O(-p md,  
本章将介绍在阿里的 Centos6.5 模板上安装 Docker 以及在 Ubuntu 14.04 模板上安装 Docker 的过程 'gf[Wjb,%  
###Centos 6.5 模板上使用Docker oP,*H6)i  
首先,通过 ssh 登陆阿里云的服务器,查看系统版本号以及内核版本。 A)U"F&tvm  
gy.UTAs N  
```sh CP7Fe{P  
Welcome to aliyun Elastic Compute Service! j}uL  
# lsb_release -a 7p1Y g  
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch uyYV_Q0~;  
Distributor ID: CentOS V}s/knd  
Description:    CentOS release 6.5 (Final)  R0Vt_7  
Release:        6.5 ^{}G4BEY  
Codename:       Final !,`'VQw$  
# uname -a h?xgOb!4  
Linux xxxxxxx 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux hL3up]pZ  
``` 9)VAEyv  
####升级内核 pbx*Y`v  
因为 Docker 推荐使用 3.8 以上内核,所以我们选择使用 YUM 方式来升级内核。 Lp&nO  
}h^ fX  
导入 KEY ,安装软件源。在 YUM 的 ELRepo 源中,有 mainline(3.13.1)、long-term(3.10.28)这 2 个内核版本,考虑到 long-term 更稳定,会长期更新,所以选择这个版本。 0 PYYG  
```sh + +L7*1t  
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org 3= =["hO  
# yum --enablerepo=elrepo-kernel install kernel-lt -y 5sJ>+Rg  
Loaded plugins: security O<$w-(  
base                                                                                                                          | 3.7 kB     00:00 .:?v;rYk{  
base/primary_db                                                                                                               | 4.6 MB     00:00 Z,)H f  
elrepo                                                                                                                        | 2.9 kB     00:00 RW&o3_Ua  
elrepo/primary_db                                                                                                             | 709 kB     00:46 L/u|90) L  
elrepo-kernel                                                                                                                 | 2.9 kB     00:00 Tr?p/9.m  
elrepo-kernel/primary_db                                                                                                      |  20 kB     00:01 {"'M2w:|D1  
epel                                                                                                                          | 4.4 kB     00:00 li%@HdA!  
epel/primary_db                                                                                                               | 6.3 MB     00:01 AOg'4  
extras                                                                                                                        | 3.4 kB     00:00 5ngs1ZF@  
extras/primary_db                                                                                                             |  29 kB     00:00 &4OJJ9S  
updates                                                                                                                       | 3.4 kB     00:00 % G!!0V!  
updates/primary_db                                                                                                            | 181 kB     00:00 \ aJ>?   
Setting up Install Process X`g<"Ka  
Resolving Dependencies ,WE2.MWR  
--> Running transaction check P*"c!Dn  
---> Package kernel-lt.x86_64 0:3.10.59-1.el6.elrepo will be installed 7g*!6-W[  
--> Finished Dependency Resolution iFUiw&  
PY.HZ/#d  
Dependencies Resolved Y^]n>X  
x_7$g<n  
===================================================================================================================================================== |.9PwD8~VD  
Package                         Arch                         Version                                      Repository                           Size ' wl})  
===================================================================================================================================================== 9Buss+K?/h  
Installing: q;9X8 _  
kernel-lt                       x86_64                       3.10.59-1.el6.elrepo                         elrepo-kernel                        33 M [7><^?t V  
bg|$1ue  
Transaction Summary b,Eq-Z;  
===================================================================================================================================================== ;jgf,fbM  
Install       1 Package(s) ;.jj>1=Tnl  
q#j[0,^ $  
Total download size: 33 M SXsszb:_  
Installed size: 153 M IS8 sJ6")  
Downloading Packages: {U-z(0  
kernel-lt-3.10.59-1.el6.elrepo.x86_64.rpm                                                                                     |  33 MB     28:58 /cClV"S*G  
Running rpm_check_debug \L>XF'o  
Running Transaction Test ddL3wQ  
Transaction Test Succeeded E0qJ.v  
Running Transaction ;*rGZ?%*  
Warning: RPMDB altered outside of yum. N]yT/8  
  Installing : kernel-lt-3.10.59-1.el6.elrepo.x86_64                                                                                             1/1 ` u3kP  
  Verifying  : kernel-lt-3.10.59-1.el6.elrepo.x86_64                                                                                             1/1 :#vA5kC  
~d&&\EZ  
Installed: =X(N+(1~  
  kernel-lt.x86_64 0:3.10.59-1.el6.elrepo Zs^zD;zU  
* 0K]/tn<  
Complete! #U0| j?!D  
)Fd)YJVR  
``` mmwc'-jU:  
`vi /etc/grub.conf ` 修改默认的启动内核,新安装的内核一般在第一个,这里把 `default = 1` 改为 `default = 0` 就好了。 bh" Caz.(t  
```sh #l>r9Z71  
default=1 5<X"+`=9  
timeout=5 B_#M)d O  
splashimage=(hd0,0)/boot/grub/splash.xpm.gz KdiJ'K.  
hiddenmenu #U'}g *  
title CentOS (3.10.59-1.el6.elrepo.x86_64) a@|`!<5  
        root (hd0,0) GwgY{-|`  
        kernel /boot/vmlinuz-3.10.59-1.el6.elrepo.x86_64 ro root=UUID=94e4e384-0ace-437f-bc96-057dd64f42ee rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet `-s]d q  
        initrd /boot/initramfs-3.10.59-1.el6.elrepo.x86_64.img  ]x1ba_  
title CentOS (2.6.32-431.23.3.el6.x86_64) MG&vduu  
        root (hd0,0) mr>E'd.'  
        kernel /boot/vmlinuz-2.6.32-431.23.3.el6.x86_64 ro root=UUID=94e4e384-0ace-437f-bc96-057dd64f42ee rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet &6GW9pl[  
        initrd /boot/initramfs-2.6.32-431.23.3.el6.x86_64.img \Pfm>$Ib=  
~ q.hpnE~#lh  
``` 4\U"e*  
重启云主机,查看内核是否升级成功。 @gx]3t*]I  
```sh 8N<2RT8W  
# uname -a gf;B&MM6  
Linux xxxxxxx 3.10.59-1.el6.elrepo.x86_64 #1 SMP Thu Oct 30 23:46:31 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux wVv@   
``` lA,[&  
####安装 Docker >U:.5Tch'V  
安装软件源,安装 Docker 软件。 skLr6Cs|  
```sh 1N.weey}W  
# yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm Zh:@A Fz:R  
# yum install docker-io {f6~Vwf  
``` :Mu]* N  
####启动 Docker E_xCRfw_i]  
安装平常的方法启动 Docker 之后,发现仍然提示有问题 w`Cs,  
```sh r*Z p-}  
# service docker start {us#(4O  
Starting cgconfig service:                                 [  OK  ] mj& 4FQ#O*  
Starting docker:                                           [  OK  ] AbMf8$$3SH  
# docker version C%P"\>5@  
Client version: 1.2.0 \S#![NC  
Client API version: 1.14 eeUEqM$7EX  
Go version (client): go1.3.3 yD^Q&1  
Git commit (client): fa7b24f/1.2.0 $Ehe8,=fj  
OS/Arch (client): linux/amd64 5F5)Bh  
2014/11/05 21:03:08 Cannot connect to the Docker daemon. Is 'docker -d' running on this host? OYIH**?  
``` sc# q03  
使用 `docker -d` 来查看详细的启动过程。 78zwu<ET  
```sh /n1H; ~f]  
# docker -d YLNJ4nE  
2014/11/05 21:10:56 docker daemon: 1.2.0 fa7b24f/1.2.0; execdriver: native; graphdriver: Z=144n 1  
[40a2dcc2] +job serveapi(unix:///var/run/docker.sock) O&PrO+&  
[info] Listening for HTTP on unix (/var/run/docker.sock) FHyyZ{"  
[40a2dcc2] +job init_networkdriver() !X{>?.@~  
[40a2dcc2.init_networkdriver()] creating new bridge for docker0 '_M"yg6d  
Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0' D"s ]dQ$r  
[40a2dcc2] -job init_networkdriver() = ERR (1) L%[b6<  
2014/11/05 21:10:56 Could not find a free IP address range for interface 'docker0'. Please configure its address manually and run 'docker -b docker0' [G}l;  
``` ,a@jg&Mb]  
提示我们没有空余 `ip` 分配给 `docker0` 了。 5cSqo{|En  
j !rQa^   
那我们就使用 `--bip` 参数来手工分配给 ip 地址。比如: MryY<s  
```sh iriF'(1  
# docker --bip=192.168.100.1/24 -d & {edjvPlk  
[2] 2388 ^U{SUWl  
[root@iZ23pznlje4Z ~]# 2014/11/05 21:16:55 docker daemon: 1.2.0 fa7b24f/1.2.0; execdriver: native; graphdriver: {$qLMx';  
[dc6906e7] +job serveapi(unix:///var/run/docker.sock) \XgpwvO".  
[info] Listening for HTTP on unix (/var/run/docker.sock) ood,k{  
[dc6906e7] +job init_networkdriver() (Q][d+} /  
[dc6906e7] -job init_networkdriver() = OK (0) H1kxY]_/  
2014/11/05 21:16:55 WARNING: Your kernel does not support cgroup swap limit. 4X:S#z  
[info] Loading containers: HF]|>1WV[  
[info] : done. 4A~1Z,"%v(  
[dc6906e7] +job acceptconnections() A\};^Y  
[dc6906e7] -job acceptconnections() = OK (0) -|3feYb'  
``` 2:Q2w3Xe  
这里提示警告 `Your kernel does not support cgroup swap limit.`,我们可以使用 `lxc-checkconfig ` 来检查。 e"ur+7  
```sh z!:%Hbh=  
# lxc-checkconfig ! 6: X]  
Kernel configuration not found at /proc/config.gz; searching... M"<B@p]rk:  
Kernel configuration found at /boot/config-3.10.59-1.el6.elrepo.x86_64 ;*409 P  
--- Namespaces --- 9w( Wtw'  
Namespaces: enabled 3=xN)j#B  
Utsname namespace: enabled w>Y!5RnO  
Ipc namespace: enabled H m Z*  
Pid namespace: enabled {S5H H"  
User namespace: missing MWron_xg  
Network namespace: enabled ntt:>j$  
Multiple /dev/pts instances: enabled Q"=$.M~  
[5sa1$n96G  
--- Control groups ---  ]pP:  
Cgroup: enabled ,f?+QV\T.  
Cgroup clone_children flag: enabled G [$u`mxV^  
Cgroup device: enabled aX{i   
Cgroup sched: enabled wwD?i.3  
Cgroup cpu account: enabled  El:&  
Cgroup memory controller: enabled BEnIyVU;L  
Cgroup cpuset: enabled KBkS>0;X  
b?{\t;  
--- Misc --- EQ> ]~  
Veth pair device: enabled ym.:I@b?6  
Macvlan: enabled iW,fKXuo&y  
Vlan: enabled  {;| >Qn  
File capabilities: enabled yV/A%y-P  
( !=^(Nd  
Note : Before booting a new kernel, you can check its configuration sbV {RSl  
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig g;G]Xi.B}  
``` &yN/ AY`U  
可以看到 `Control groups` 项目都是支持的,所以我们暂时忽略这个告警。 a1yGgT a?D  
####测试使用 "[t b-$ER  
由于 Aliyun 的网络直接 pull 官方镜像也不是很稳定,这里推荐使用 `Dockerpool` 官方网站的标准`ubuntu`镜像来测试。 HHcWyu  
JuTIP6 /G  
下载镜像,重新标记镜像。 "D1u2>(  
```sh l6#ms!e  
# docker pull dl.dockerpool.com:5000/ubuntu:14.04 C])b 3tM,7  
# docker images LOf)D7T  
REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE h1+lVAQbT  
dl.dockerpool.com:5000/ubuntu   latest              5506de2b643b        12 days ago         197.8 MB uA~T.b\  
# docker tag 550 ubuntu h#Q Sx@U6  
# docker rmi dl.dockerpool.com:5000/ubuntu C6ry]R@  
[dc6906e7] +job image_delete(dl.dockerpool.com:5000/ubuntu) . \:{6_  
[dc6906e7] +job log(untag, 5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5, ) g6p:1;Evf  
[dc6906e7] -job log(untag, 5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5, ) = OK (0) KKJ)BG?qZ  
[dc6906e7] -job image_delete(dl.dockerpool.com:5000/ubuntu) = OK (0) g886RhCe  
Untagged: dl.dockerpool.com:5000/ubuntu:latest !aQQq[  
``` Kp)H>~cL  
启动容器,并测试网络。 `#x}-A$  
```sh }{S f*  
# docker run -ti ubuntu :7Jpt3  
root@66ff9a55a4f5:/# ping www.dockerpool.com u/>+cT6}  
PING www.dockerpool.com (xxx.xxx.xxx.xxx) 56(84) bytes of data. |';oIYs|$  
^C64 bytes from 203.195.193.251: icmp_seq=1 ttl=47 time=31.4 ms Tw+V$:$$  
``` 5%1a!M M M  
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容