Docker.io 是輕量級的“容器引擎+映像倉庫”,在LXC(linux輕量級容器)的基礎上構建,可以執行任何應用程式。
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有衝突,所以需要禁用
[[email protected] ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
2、配置Fedora EPEL 源
sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
3、配置hop5.in源
cd /etc/yum.repos.d
sudo wget http://www.hop5.in/yum/el6/hop5.repo
4、安裝docker-io
[[email protected] ~]# yum install docker-io
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: kartolo.sby.datautama.net.id
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package docker-io.x86_64 0:0.5.3-4.el6 will be installed
--> Processing Dependency: lxc >= 0.8.0 for package: docker-io-0.5.3-4.el6.x86_64
--> Processing Dependency: kernel-ml-aufs >= 3.10.5 for package: docker-io-0.5.3-4.el6.x86_64
--> Running transaction check
---> Package kernel-ml-aufs.x86_64 0:3.10.5-3.el6 will be installed
---> Package lxc.x86_64 0:0.8.0-3.el6 will be installed
--> Processing Dependency: liblxc.so.0()(64bit) for package: lxc-0.8.0-3.el6.x86_64
--> Running transaction check
---> Package lxc-libs.x86_64 0:0.8.0-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================
Package Arch Version Repository Size
============================================================================================
Installing:
docker-io x86_64 0.5.3-4.el6 hop5 1.2 M
Installing for dependencies:
kernel-ml-aufs x86_64 3.10.5-3.el6 hop5 33 M
lxc x86_64 0.8.0-3.el6 hop5 81 k
lxc-libs x86_64 0.8.0-3.el6 hop5 75 k
Transaction Summary
============================================================================================
Install 4 Package(s)
Total download size: 34 M
Installed size: 159 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): docker-io-0.5.3-4.el6.x86_64.rpm | 1.2 MB 00:03
(2/4): kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm | 33 MB 00:33
(3/4): lxc-0.8.0-3.el6.x86_64.rpm | 81 kB 00:00
(4/4): lxc-libs-0.8.0-3.el6.x86_64.rpm | 75 kB 00:00
--------------------------------------------------------------------------------------------
Total 896 kB/s | 34 MB 00:39
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lxc-libs-0.8.0-3.el6.x86_64 1/4
Installing : lxc-0.8.0-3.el6.x86_64 2/4
Installing : kernel-ml-aufs-3.10.5-3.el6.x86_64 3/4
Installing : docker-io-0.5.3-4.el6.x86_64 4/4
Verifying : kernel-ml-aufs-3.10.5-3.el6.x86_64 1/4
Verifying : lxc-0.8.0-3.el6.x86_64 2/4
Verifying : lxc-libs-0.8.0-3.el6.x86_64 3/4
Verifying : docker-io-0.5.3-4.el6.x86_64 4/4
Installed:
docker-io.x86_64 0:0.5.3-4.el6
Dependency Installed:
kernel-ml-aufs.x86_64 0:3.10.5-3.el6 lxc.x86_64 0:0.8.0-3.el6
lxc-libs.x86_64 0:0.8.0-3.el6
Complete!
[[email protected] ~]#
5、檢查安裝情況
[[email protected] ~]# docker -h
Usage of docker:
-D=false: Debug mode
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use
-api-enable-cors=false: Enable CORS requests in the remote api.
-b="": Attach containers to a pre-existing network bridge. Use 'none' to disable container networking
-d=false: Daemon mode
-dns="": Set custom dns servers
-g="/var/lib/docker": Path to graph storage base dir.
-p="/var/run/docker.pid": File containing process PID
-r=false: Restart previously running containers
6、要想docker正常執行還需要在/etc/fstab裡增加cgroup檔案系統
[[email protected] ~]# echo "none /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab
[[email protected] ~]# mount /sys/fs/cgroup
只有重新啟動才能掛載/sys/fs/cgroup(因為當前執行的核心不支援cgroup),所以上面掛載的命令也可以不執行,但系統需要重新啟動。
7、重啟系統,選擇“3.10.5-3.el6.x86_64”核心
8、系統啟動後,確認當前執行的核心
[[email protected] ~]# uname -r
3.10.5-3.el6.x86_64
[[email protected] ~]# grep aufs /proc/filesystems
nodev aufs
9、以守護模式執行docker.io(在一個新的終端裡)
[[email protected] ~]# 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)
10、在centos6.4容器裡輸出hello world
[[email protected] ~]# 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=1&stderr=1&stdout=1&stream=1
hello world
11、從容器裡測試ping
[[email protected] ~]# 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=1&stderr=1&stdout=1&stream=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
常見錯誤:
"DNS/Networking Errors inside the docker"
[[email protected] ~]# docker -dns="8.8.8.8" run centos:6.4 yum install hiphop-php
2013/08/21 07:53:05 POST /v1.4/containers/create
2013/08/21 07:53:05 POST /v1.4/containers/6d9fef14bd1a/start
2013/08/21 07:53:05 POST /v1.4/containers/6d9fef14bd1a/attach?logs=1&stderr=1&stdout=1&stream=1
Loaded plugins: fastestmirror
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
可以執行下面的命令來重置docker的執行環境,從而解決上述問題。
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d
感謝sciurus在建立kernel-ml-aufs的相關檔案時付出的辛勤工作。
相關文章
- Jquery實現的Switch開關按鈕(仿iOS開關)
- 《Hierarchical Text-Conditional Image Generation with CLIP Latents》閱讀筆記
- 關於 .NET 在不同作業系統中 IO 檔案路徑拼接方法結升級 .NET 7 後注意到的一個小坑
- Presto + Alluxio:B站資料庫系統效能提升實踐
- iToolab AnyGo for Mac(iOS虛擬定位工具)
- 在連結串列上實現 Partition 以及荷蘭國旗問題
- 【高併發】由InterruptedException異常引發的思考
- 如何在Mac上使用Docker
- OpenGuass Exception: [GAUSS-52200] : When compiling python
- BSN開放聯盟鏈“武漢鏈”新版瀏覽器wuscan.io正式上線釋出
- InterruptedException異常會對併發程式設計產生哪些影響?
- 學習 vue3 第一天 vue3簡介,建立vue3專案 Composition Api 初識
- DBMotion——MySQL遷移利器
- Java Web中requset,session,application 的作用域及區別
- Win10 Version 22H2 會是微軟 Windows 10 最後一個功能更新嗎
- 錢包被駭客入侵後,IOTA 加密貨幣關閉了整個網路