天天看點

在 CentOS 6.4(64位) 安裝 docker.io

docker.io 是輕量級的“容器引擎+映像倉庫”,在lxc(linux輕量級容器)的基礎上建構,可以運作任何應用程式。

在 CentOS 6.4(64位) 安裝 docker.io

docker.io的核心層由以下幾個部分組成:

1、可執行程式,“/usr/bin/docker”

2、docker.io網站上有一系列建立好的作業系統和應用程式映像

3、aufs(另一個統一檔案系統)來實作檔案系統的快照,檔案變化,控制隻讀或讀寫的需求。

4、lxc(linux輕量級容器)

5、cgroups(各種資源和命名空間的管理)

在本文寫作的時候,最新版本是0.5.3,但目前開發很活躍,一些功能和特性可能在新版本中會發生變化。

按下面的步驟安裝docker.io:

0、安裝centos6.x

1、因為selinux和lxc有沖突,是以需要禁用

<code>[root@localhost ~]# cat /etc/selinux/config</code>

<code># this file controls the state of selinux on the system.</code>

<code># selinux= can take one of these three values:</code>

<code># enforcing - selinux security policy is enforced.</code>

<code># permissive - selinux prints warnings instead of enforcing.</code>

<code># disabled - selinux is fully disabled.</code>

<code>selinux=disabled</code>

<code># selinuxtype= type of policy in use. possible values are:</code>

<code># targeted - only targeted network daemons are protected.</code>

<code># strict - full selinux protection.</code>

<code>selinuxtype=targeted</code>

<code>sudo yum install http://ftp.riken.jp/linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm</code>

3、配置hop5.in源

<code>cd /etc/yum.repos.d</code>

<code>sudo wget http://www.hop5.in/yum/el6/hop5.repo</code>

4、安裝docker-io

<code>[root@localhost ~]# yum install docker-io</code>

<code>loaded plugins: fastestmirror, security</code>

<code>loading mirror speeds from cached hostfile</code>

<code>* base: centos.excellmedia.net</code>

<code>* epel: kartolo.sby.datautama.net.id</code>

<code>* extras: centos.excellmedia.net</code>

<code>* updates: centos.excellmedia.net</code>

<code>setting up install process</code>

<code>resolving dependencies</code>

<code>--&gt; running transaction check</code>

<code>---&gt; package docker-io.x86_64 0:0.5.3-4.el6 will be installed</code>

<code>--&gt; processing dependency: lxc &gt;= 0.8.0 for package: docker-io-0.5.3-4.el6.x86_64</code>

<code>--&gt; processing dependency: kernel-ml-aufs &gt;= 3.10.5 for package: docker-io-0.5.3-4.el6.x86_64</code>

<code>---&gt; package kernel-ml-aufs.x86_64 0:3.10.5-3.el6 will be installed</code>

<code>---&gt; package lxc.x86_64 0:0.8.0-3.el6 will be installed</code>

<code>--&gt; processing dependency: liblxc.so.0()(64bit) for package: lxc-0.8.0-3.el6.x86_64</code>

<code>---&gt; package lxc-libs.x86_64 0:0.8.0-3.el6 will be installed</code>

<code>--&gt; finished dependency resolution</code>

<code></code>

<code>dependencies resolved</code>

<code>============================================================================================</code>

<code>package arch version repository size</code>

<code>installing:</code>

<code>docker-io x86_64 0.5.3-4.el6 hop5 1.2 m</code>

<code>installing for dependencies:</code>

<code>kernel-ml-aufs x86_64 3.10.5-3.el6 hop5 33 m</code>

<code>lxc x86_64 0.8.0-3.el6 hop5 81 k</code>

<code>lxc-libs x86_64 0.8.0-3.el6 hop5 75 k</code>

<code>transaction summary</code>

<code>install 4 package(s)</code>

<code>total download size: 34 m</code>

<code>installed size: 159 m</code>

<code>is this ok [y/n]: y</code>

<code>downloading packages:</code>

<code>(1/4): docker-io-0.5.3-4.el6.x86_64.rpm | 1.2 mb 00:03</code>

<code>(2/4): kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm | 33 mb 00:33</code>

<code>(3/4): lxc-0.8.0-3.el6.x86_64.rpm | 81 kb 00:00</code>

<code>(4/4): lxc-libs-0.8.0-3.el6.x86_64.rpm | 75 kb 00:00</code>

<code>--------------------------------------------------------------------------------------------</code>

<code>total 896 kb/s | 34 mb 00:39</code>

<code>running rpm_check_debug</code>

<code>running transaction test</code>

<code>transaction test succeeded</code>

<code>running transaction</code>

<code>installing : lxc-libs-0.8.0-3.el6.x86_64 1/4</code>

<code>installing : lxc-0.8.0-3.el6.x86_64 2/4</code>

<code>installing : kernel-ml-aufs-3.10.5-3.el6.x86_64 3/4</code>

<code>installing : docker-io-0.5.3-4.el6.x86_64 4/4</code>

<code>verifying : kernel-ml-aufs-3.10.5-3.el6.x86_64 1/4</code>

<code>verifying : lxc-0.8.0-3.el6.x86_64 2/4</code>

<code>verifying : lxc-libs-0.8.0-3.el6.x86_64 3/4</code>

<code>verifying : docker-io-0.5.3-4.el6.x86_64 4/4</code>

<code>installed:</code>

<code>docker-io.x86_64 0:0.5.3-4.el6</code>

<code>dependency installed:</code>

<code>kernel-ml-aufs.x86_64 0:3.10.5-3.el6 lxc.x86_64 0:0.8.0-3.el6</code>

<code>lxc-libs.x86_64 0:0.8.0-3.el6</code>

<code>complete!</code>

<code>[root@localhost ~]#</code>

5、檢查安裝情況

<code>[root@localhost ~]# docker -h</code>

<code>usage of docker:</code>

<code>-d=false: debug mode</code>

<code>-h=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use</code>

<code>-api-enable-cors=false: enable cors requests in the remote api.</code>

<code>-b="": attach containers to a pre-existing network bridge. use 'none' to disable container networking</code>

<code>-d=false: daemon mode</code>

<code>-dns="": set custom dns servers</code>

<code>-g="/var/lib/docker": path to graph storage base dir.</code>

<code>-p="/var/run/docker.pid": file containing process pid</code>

<code>-r=false: restart previously running containers</code>

6、要想docker正常運作還需要在/etc/fstab裡增加cgroup檔案系統

<code>[root@localhost ~]# echo "none /sys/fs/cgroup cgroup defaults 0 0" &gt;&gt; /etc/fstab</code>

<code>[root@localhost ~]# mount /sys/fs/cgroup</code>

隻有重新啟動才能挂載/sys/fs/cgroup(因為目前運作的核心不支援cgroup),是以上面挂載的指令也可以不執行,但系統需要重新啟動。

7、重新開機系統,選擇“3.10.5-3.el6.x86_64”核心

8、系統啟動後,确認目前運作的核心

<code>[root@localhost ~]# uname -r</code>

<code>3.10.5-3.el6.x86_64</code>

<code>[root@localhost ~]# grep aufs /proc/filesystems</code>

<code>nodev aufs</code>

9、以守護模式運作docker.io(在一個新的終端裡)

<code>[root@localhost ~]# docker -d</code>

<code>2013/08/21 07:47:07 warning: your kernel does not support cgroup swap limit.</code>

<code>2013/08/21 07:47:07 listening for http on /var/run/docker.sock (unix)</code>

10、在centos6.4容器裡輸出hello world

<code>[root@localhost ~]# docker run centos:6.4 echo "hello world"</code>

<code>2013/08/21 07:48:41 post /v1.4/containers/create</code>

<code>2013/08/21 07:48:41 post /v1.4/containers/c6bc9e80097e/start</code>

<code>2013/08/21 07:48:41 post /v1.4/containers/c6bc9e80097e/attach?logs=1&amp;stderr=1&amp;stdout=1&amp;stream=1</code>

<code>hello world</code>

11、從容器裡測試ping

<code>[root@localhost ~]# docker -dns '8.8.8.8' run centos:6.4 ping -c 3 yahoo.com</code>

<code>2013/08/21 08:02:15 post /v1.4/containers/create</code>

<code>2013/08/21 08:02:15 post /v1.4/containers/c40a1244f9bc/start</code>

<code>2013/08/21 08:02:15 post /v1.4/containers/c40a1244f9bc/attach?logs=1&amp;stderr=1&amp;stdout=1&amp;stream=1</code>

<code>ping yahoo.com (98.138.253.109) 56(84) bytes of data.</code>

<code>64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=48 time=323 ms</code>

<code>64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=2 ttl=48 time=329 ms</code>

<code>64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=3 ttl=49 time=302 ms</code>

<code>--- yahoo.com ping statistics ---</code>

<code>3 packets transmitted, 3 received, 0% packet loss, time 2304ms</code>

<code>rtt min/avg/max/mdev = 302.032/318.318/329.656/11.807 ms</code>

常見錯誤:

"dns/networking errors inside the docker"

<code>[root@localhost ~]# docker -dns="8.8.8.8" run centos:6.4 yum install hiphop-php</code>

<code>2013/08/21 07:53:05 post /v1.4/containers/create</code>

<code>2013/08/21 07:53:05 post /v1.4/containers/6d9fef14bd1a/start</code>

<code>2013/08/21 07:53:05 post /v1.4/containers/6d9fef14bd1a/attach?logs=1&amp;stderr=1&amp;stdout=1&amp;stream=1</code>

<code>loaded plugins: fastestmirror</code>

<code>error: cannot retrieve repository metadata (repomd.xml) for repository: base. please verify its path and try again</code>

<code>could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&amp;arch=x86_64&amp;repo=os error was</code>

<code>14: pycurl error 6 - "couldn't resolve host 'mirrorlist.centos.org'"</code>

可以執行下面的指令來重置docker的運作環境,進而解決上述問題。

<code>pkill docker</code>

<code>iptables -t nat -f</code>

<code>ifconfig docker0 down</code>

<code>brctl delbr docker0</code>

<code>docker -d</code>

原文釋出時間為:2014-01-03

本文來自雲栖社群合作夥伴“linux中國”

繼續閱讀