设为首页 收藏本站
查看: 885|回复: 0

[经验分享] Installing docker.io on centos 6.4 (64-bit)

[复制链接]

尚未签到

发表于 2015-10-13 09:22:50 | 显示全部楼层 |阅读模式

Installing docker.io on centos 6.4 (64-bit)



NOTES: epel has another package called docker (which is a KDE docking application and is not related to this). So, you will get an error performing these steps, if you have that package already
installed.



UPDATE-1: Docker version-0.6.1 is released. Upgrade instructions are available
here




UPDATE-2: Docker version-0.6.2 is released.  



Docker.io is the lightweight "container engine + image repository" built on top of LXC (linux lightweight containers) to ship any application.



At the core of docker.io there are


  • an application "/usr/bin/docker"
  • set of pre-created operating-system/application images hosted with "docker.io"
  • AUFS (Another Union filesystem) to take care of snapshots, diffs, ro/rw requirements
  • LXC (Linux lightweight containers)
  • cgroups (for resource management and namespacing)

As of writing this blog, the latest version is 0.5.3 . The project is actively being developed and things can change in near future.



Follow these instructions to get docker.io installed on your system.



0. Install centos 6.x



1. Disable selinux as it interferes with functionality of LXC



[iyunv@localhost ~]# 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. Download and setup Fedora EPEL Repository



sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm


3. Setup hop5.in repository



cd /etc/yum.repos.d
sudo wget http://www.hop5.in/yum/el6/hop5.repo


4. Install docker-io package



[iyunv@localhost ~]# 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!
[iyunv@localhost ~]#



5. See the package is installed correctly



[iyunv@localhost ~]# 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. Add cgroup filesystem to /etc/fstab , so that docker will work correctly



[iyunv@localhost ~]# echo "none                    /sys/fs/cgroup          cgroup  defaults        0 0" >> /etc/fstab
[iyunv@localhost ~]# mount /sys/fs/cgroup


Per "Peter Zimmerman" a reboot is needed to actually mount /sys/fs/cgroup (due to the kernel doesn't have cgroup support). So, the above mount step is not really needed. As its used only upon reboot.



7. Reboot the system ; make sure to select "3.10.5-3.el6.x86_64" kernel version while booting.



8. Once system is up and running, make sure you are on right kernel



[iyunv@localhost ~]# uname -r
3.10.5-3.el6.x86_64
[iyunv@localhost ~]# grep aufs /proc/filesystems
nodev   aufs

9. Start the docker.io in daemon mode (in a different terminal)



[iyunv@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)


10. Print hello world from a centos 6.4 container.



[iyunv@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=1&stderr=1&stdout=1&stream=1
hello world



11. Ping from inside the container

[iyunv@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=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
TROUBLESHOOTING

"DNS/Networking Errors inside the docker"


[iyunv@localhost ~]# 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'"




Please issue the following commands, so that docker and its environment will be
reset and above issue will be taken care of.


pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d


following commands:
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d
It will force docker to recreate the bridge and reinit all the network rules






CREDITS: Thanks to sciurus for doing the hardwork in
creating the spec file for kernel-ml-aufs.




原文地址


初始化脚本一个:


!/bin/bash
### BEGIN INIT INFO
# INIT INFO
# Provides:          docker
# Required-Start:    networking
# Required-Stop:     networking
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: docker
# Description:       docker
### END INIT INFO
. /etc/init.d/functions
NAME=docker
PID_FILE="/var/run/${NAME}.pid"
DELAY=0
status_q() {
status -p $PID_FILE $NAME > /dev/null
return $?
}
start_app() {
nohup /usr/bin/docker -d >/var/log/docker.log 2>&1 </dev/null &
return $?
}
start() {
status_q; res=$?
if [ $res -eq 3 ]; then
echo -n $&quot;$NAME starting...&quot;
start_app
echo $! > $PID_FILE
[ $DELAY -gt 0 ] && sleep $DELAY
status_q; res=$?
[ $res -eq 0 ] && success || failure
echo
elif [ $res -eq 0 ]; then
success; echo &quot;$NAME is already running&quot;
else
failure; echo &quot;$NAME is not running, res: $res&quot;
fi
return $res
}
stop() {
status_q; res=$?
if [ $res -eq 3 ]; then
success && echo &quot;$NAME is not running&quot;
else
killproc -p $PID_FILE; res=$?
if [ $res -eq 0 ]; then
rm -f PID_FILE
success && echo &quot;$NAME has been stopped&quot;
else
failure && echo &quot;$NAME cannot be stopped ($res)&quot;
fi
fi
return $res
}
case $1 in
start)
start
exit $?
;;
stop)
stop
exit $?
;;
status)
echo -n $&quot;$NAME running...&quot;
status_q; res=$?
[ $res -eq 0 ] && success || failure
echo
exit $res
;;
restart)
stop
start
exit $?
;;
*)
echo &quot;Usage: $0 {start|stop|restart|status}&quot;
exit 2
;;
esac




其他链接:
http://qing.blog.sina.com.cn/2294942122/88ca09aa33003ydp.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126132-1-1.html 上篇帖子: Docker:一点思考 下篇帖子: docker run --lxc-conf 配置项使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表