佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > CentOS6.x上部署Docker容器環(huán)境的全流程攻略

CentOS6.x上部署Docker容器環(huán)境的全流程攻略

熱門標簽:硅谷的囚徒呼叫中心 智能手機 網(wǎng)站建設(shè) 服務(wù)外包 Win7旗艦版 Linux服務(wù)器 免費建站 百度競價排名

Docker.io 是輕量級的“容器引擎+映像倉庫”,在LXC(linux輕量級容器)的基礎(chǔ)上構(gòu)建,可以運行任何應(yīng)用程序。
docker.io的核心層由以下幾個部分組成:
1、可執(zhí)行程序,“/usr/bin/docker”
2、docker.io網(wǎng)站上有一系列創(chuàng)建好的操作系統(tǒng)和應(yīng)用程序映像
3、AUFS(另一個統(tǒng)一文件系統(tǒng))來實現(xiàn)文件系統(tǒng)的快照,文件變化,控制只讀或讀寫的需求。
4、LXC(Linux輕量級容器)
5、Cgroups(各種資源和命名空間的管理)
在本文寫作的時候,最新版本是0.5.3,但目前開發(fā)很活躍,一些功能和特性可能在新版本中會發(fā)生變化。
需要注意的是CentOS 6.5與7.0的安裝是有一點點不同的,CentOS-6上docker的安裝包叫docker-io,并且來源于Fedora epel庫,這個倉庫維護了大量的沒有包含在發(fā)行版中的軟件,所以先要安裝EPEL,而CentOS-7的docker直接包含在官方鏡像源的Extras倉庫(CentOS-Base.repo下的[extras]節(jié)enable=1啟用)。前提是都需要聯(lián)網(wǎng),具體安裝過程如下。

1. 禁用selinux
[/code]
# getenforce
enforcing
# setenforce 0
permissive
# vi /etc/selinux/config
SELINUX=disabled
...
[/code]
2. 安裝 Fedora EPEL
epel-release-6-8.noarch.rpm包在發(fā)行版的介質(zhì)里面已經(jīng)自帶了,可以從rpm安裝。

復(fù)制代碼
代碼如下:

# yum install epel-release-6-8.noarch.rpm
//或
yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

如果出現(xiàn)GPG key retrieval failed: [Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6問題,請在線安裝epel,下載RPM-GPG-KEY-EPEL-6文件。
這一步執(zhí)行之后,會在/etc/yum.repos.d/下生成epel.repo、epel-testing.repo兩個文件,用于從Fedora官網(wǎng)下載rpm包。

3. 檢查內(nèi)核版本

復(fù)制代碼
代碼如下:

# uname -r
2.6.32-431.el6.x86_64
# cat /etc/redhat-release
CentOS release 6.5 (Final)

看到這個最低的內(nèi)核版本,事實運行起來是沒太大問題的,你也可以升級到3.10.x版本。
另外你也可以運行腳本check-config.sh,來檢查內(nèi)核模塊符不符合(下面有些missing的,我的docker還是可以正常啟動):

復(fù)制代碼
代碼如下:

[root@sean ~]# ./check-config
warning: /proc/config.gz does not exist, searching other paths for kernel config...
info: reading kernel config from /boot/config-2.6.32-431.el6.x86_64 ...
Generally Necessary:
- cgroup hierarchy: properly mounted [/cgroup]
- CONFIG_NAMESPACES: enabled
- CONFIG_NET_NS: enabled
- CONFIG_PID_NS: enabled
- CONFIG_IPC_NS: enabled
- CONFIG_UTS_NS: enabled
- CONFIG_DEVPTS_MULTIPLE_INSTANCES: enabled
- CONFIG_CGROUPS: enabled
- CONFIG_CGROUP_CPUACCT: enabled
- CONFIG_CGROUP_DEVICE: enabled
- CONFIG_CGROUP_FREEZER: enabled
- CONFIG_CGROUP_SCHED: enabled
- CONFIG_MACVLAN: enabled
- CONFIG_VETH: enabled
- CONFIG_BRIDGE: enabled
- CONFIG_NF_NAT_IPV4: missing
- CONFIG_IP_NF_TARGET_MASQUERADE: enabled
- CONFIG_NETFILTER_XT_MATCH_ADDRTYPE: missing
- CONFIG_NETFILTER_XT_MATCH_CONNTRACK: enabled
- CONFIG_NF_NAT: enabled
- CONFIG_NF_NAT_NEEDED: enabled
Optional Features:
- CONFIG_MEMCG_SWAP: missing
- CONFIG_RESOURCE_COUNTERS: enabled
- CONFIG_CGROUP_PERF: enabled
- Storage Drivers:
- "aufs":
- CONFIG_AUFS_FS: missing
- CONFIG_EXT4_FS_POSIX_ACL: enabled
- CONFIG_EXT4_FS_SECURITY: enabled
- "btrfs":
- CONFIG_BTRFS_FS: enabled
- "devicemapper":
- CONFIG_BLK_DEV_DM: enabled
- CONFIG_DM_THIN_PROVISIONING: enabled
- CONFIG_EXT4_FS: enabled
- CONFIG_EXT4_FS_POSIX_ACL: enabled
- CONFIG_EXT4_FS_SECURITY: enabled
  
假如你是自己編譯內(nèi)核,請?zhí)貏e留意幾個絕對不能缺少的:DM_THIN_PROVISIONING、IP_NF_TARGET_MASQUERADE、NF_NAT。(AUFS_FS沒有對應(yīng)選項,還不清楚怎么回事,但不是必須)

4. 安裝 docker-io

復(fù)制代碼
代碼如下:

# yum install docker-io
Dependencies Resolved
===========================================================================================
Package Arch Version Repository Size
===========================================================================================
Installing:
docker-io x86_64 1.1.2-1.el6 epel 4.5 M
Installing for dependencies:
lua-alt-getopt noarch 0.7.0-1.el6 epel 6.9 k
lua-filesystem x86_64 1.4.2-1.el6 epel 24 k
lua-lxc x86_64 1.0.6-1.el6 epel 15 k
lxc x86_64 1.0.6-1.el6 epel 120 k
lxc-libs x86_64 1.0.6-1.el6 epel 248 k
Transaction Summary
===========================================================================================
Install 6 Package(s)

許多文檔介紹到這里,下一步為掛載/cgroup文件系統(tǒng),我的docker版本為1.1.2,沒有修改/etc/fstab的步驟。

5. 啟動試運行

復(fù)制代碼
代碼如下:

# service docker start
//或
# docker -d

6. 以守護模式運行docker.io(在一個新的終端里)

復(fù)制代碼
代碼如下:

[root@localhost ~]# docker -d
2013/08/21 07:47:07 WARNING: Your kernel does not support cgroup swap limit.
2013/08/21 07:47:07 Listening for HTTP on /var/run/docker.sock (unix)

7. 在centos6.4容器里輸出hello world

復(fù)制代碼
代碼如下:

[root@localhost ~]# docker run centos:6.4 echo "hello world"
2013/08/21 07:48:41 POST /v1.4/containers/create
2013/08/21 07:48:41 POST /v1.4/containers/c6bc9e80097e/start
2013/08/21 07:48:41 POST /v1.4/containers/c6bc9e80097e/attach?logs=1stderr=1stdout=1stream=1
hello world

8. 從容器里測試ping

復(fù)制代碼
代碼如下:

[root@localhost ~]# docker -dns '8.8.8.8' run centos:6.4 ping -c 3 yahoo.com
2013/08/21 08:02:15 POST /v1.4/containers/create
2013/08/21 08:02:15 POST /v1.4/containers/c40a1244f9bc/start
2013/08/21 08:02:15 POST /v1.4/containers/c40a1244f9bc/attach?logs=1stderr=1stdout=1stream=1
PING yahoo.com (98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=48 time=323 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=2 ttl=48 time=329 ms
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=3 ttl=49 time=302 ms
--- yahoo.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2304ms
rtt min/avg/max/mdev = 302.032/318.318/329.656/11.807 ms

9. 異常
在我的一次安裝過程中,很不幸遇到下面的問題:
docker -d啟動,或tail -f /var/log/docker查看日志

復(fù)制代碼
代碼如下:

[f32e7d9f] +job initserver()
[f32e7d9f.initserver()] Creating server
[f32e7d9f] +job serveapi(unix:///var/run/docker.sock)
2014/10/22 13:02:45 Listening for HTTP on unix (/var/run/docker.sock)
Error running DeviceCreate (createPool) dm_task_run failed
[f32e7d9f] -job initserver() = ERR (1)
2014/10/22 13:02:45 Error running DeviceCreate (createPool) dm_task_run failed
\nWed Oct 22 14:35:54 CST 2014\n

再或者是service docker restart

復(fù)制代碼
代碼如下:

Stopping docker: [ OK ]
Starting cgconfig service: Error: cannot mount cpuset to /cgroup/cpuset: Device or resource busy
/sbin/cgconfigparser; error loading /etc/cgconfig.conf: Cgroup mounting failed
Failed to parse /etc/cgconfig.conf [FAILED]
Starting docker: [ OK ]

全選復(fù)制放進筆記Unable to enable network bridge NAT: iptables failed: iptables -I POSTROUTING -t nat -s 172.17.42.1/16 ! -d 172.17.42.1/16 -j MASQUERADE: iptables v1.4.7: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

標簽:商丘 玉樹 石家莊 天水 棗莊 克拉瑪依 許昌 武威

巨人網(wǎng)絡(luò)通訊聲明:本文標題《CentOS6.x上部署Docker容器環(huán)境的全流程攻略》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    津市市| 永兴县| 藁城市| 饶河县| 临猗县| 玉树县| 潍坊市| 新民市| 剑阁县| 安阳市| 景谷| 苏州市| 琼结县| 枣庄市| 荔波县| 武定县| 彭阳县| 香港| 大同市| 定陶县| 赤壁市| 炎陵县| 寿光市| 锡林郭勒盟| 永顺县| 桂东县| 大埔县| 泉州市| 兴城市| 隆安县| 繁昌县| 太仆寺旗| 宁安市| 金阳县| 牡丹江市| 玉树县| 公主岭市| 新安县| 扶绥县| 聂荣县| 曲松县|