在Redhat/Centos下安装Docker(不升级内核)
2014-01-20 16:52
1181 查看
零、博客背景
由于内核版本问题,最初仅ubuntu可以较好的支持Docker。不过,由于Redhat系列OS(REHL、Centos)是目前主流的Linux服务器操作系统,所以令Redhat系列OS支持Docker很有必要。目前Docker和Redhat已经展开深入合作,并在2013年年底推出了可以在Redhat系列OS上运行的Docker0.7。
目前有一些博客介绍了如何在centos上安装Docker,例如http://www.yanjiuyanjiu.com/blog/20131025/。但是这些博客都是针对老版本的Docker,安装方法是在升级操作系统内核版本的基础上完成。问题是,我们不可以随意升级生产环境的操作系统内核版本,而且Docker0.7的主旨就是:Docker使用者可以在不升级内核的前提下,在Redhat环境这使用Docker。因此,这里撰写一篇博客,介绍如何在Redhat/Centos环境下,安装新版本的Docker。
一、禁用selinux
由于Selinux和LXC有冲突,所以需要禁用selinux。编辑/etc/selinux/config,设置两个关键变量。
二、配置Fedora EPEL源
由于内核版本问题,最初仅ubuntu可以较好的支持Docker。不过,由于Redhat系列OS(REHL、Centos)是目前主流的Linux服务器操作系统,所以令Redhat系列OS支持Docker很有必要。目前Docker和Redhat已经展开深入合作,并在2013年年底推出了可以在Redhat系列OS上运行的Docker0.7。
目前有一些博客介绍了如何在centos上安装Docker,例如http://www.yanjiuyanjiu.com/blog/20131025/。但是这些博客都是针对老版本的Docker,安装方法是在升级操作系统内核版本的基础上完成。问题是,我们不可以随意升级生产环境的操作系统内核版本,而且Docker0.7的主旨就是:Docker使用者可以在不升级内核的前提下,在Redhat环境这使用Docker。因此,这里撰写一篇博客,介绍如何在Redhat/Centos环境下,安装新版本的Docker。
一、禁用selinux
由于Selinux和LXC有冲突,所以需要禁用selinux。编辑/etc/selinux/config,设置两个关键变量。
SELINUX=disabled SELINUXTYPE=targeted
二、配置Fedora EPEL源
sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm[/code]
三、添加hop5.repo源cd /etc/yum.repos.d sudo wget http://www.hop5.in/yum/el6/hop5.repo[/code]
四、安装Dockersudo yum install docker-io图1是yum安装过程中的截图,可以发现安装的软件只有docker和lxc相关包,没有内核包,例如kernel-ml-aufs。
图1 yum install docker-io输出截图
五、初步验证docker
输入docker -h,如果有如下输出,就证明docker在形式上已经安装成功。# docker -h Usage of docker: -D=false: Enable debug mode -H=[]: Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise -api-enable-cors=false: Enable CORS headers in the remote API -b="": Attach containers to a pre-existing network bridge; use 'none' to disable container networking -bip="": Use this CIDR notation address for the network bridge's IP, not compatible with -b -d=false: Enable daemon mode -dns=[]: Force docker to use specific DNS servers -g="/var/lib/docker": Path to use as the root of the docker runtime -icc=true: Enable inter-container communication -ip="0.0.0.0": Default IP address to use when binding container ports -iptables=true: Disable docker's addition of iptables rules -p="/var/run/docker.pid": Path to use for daemon PID file -r=true: Restart previously running containers -s="": Force the docker runtime to use a specific storage driver -v=false: Print version information and quit
六、手动挂载cgroup
在redhat/centos环境中运行docker、lxc,需要手动重新挂载cgroup。
我们首选禁用cgroup对应服务cgconfig。sudo service cgconfig stop # 关闭服务 sudo chkconfig cgconfig off # 取消开机启动然后挂载cgroup,可以命令行挂载mount -t cgroup none /cgroup # 仅本次有效或者修改配置文件,编辑/etc/fstab,加入none /cgroup cgroup defaults 0 0 # 开机后自动挂载,一直有效七、调整lxc版本
Docker0.7默认使用的是lxc-0.9.0,该版本lxc在redhat上不能正常运行(具体情况可参见本人另一篇博客《Redhat下Docker、LXC、CGroup的协同配置》),需要调整lxc版本为lxc-0.7.5或者lxc-1.0.0Beta2。前者可以通过lxc网站(http://sourceforge.net/projects/lxc/files/lxc/)下载,后者需要在github上下载最新的lxc版本(https://github.com/lxc/lxc,目前版本是lxc-1.0.0Beta2)。
这里特别说明一点,由于Docker安装绝对路径/usr/bin/lxc-xxx调用lxc相关命令,所以需要将lxc-xxx安装到/usr/bin/目录下。
八、启动docker服务sudo service docker start # 启动服务 sudo chkconfig docker on # 开机启动
九、试运行sudo docker run -i -t ubuntu /bin/echo hello world初次执行此命令会先拉取镜像文件,耗费一定时间。最后应当输出hello world。
参考
Docker官方文档 http://docs.docker.io/en/latest/installation/rhel/
http://www.yanjiuyanjiu.com/blog/20131025/
http://www.oschina.net/translate/nstalling-dockerio-on-centos-64-64-bit
相关文章推荐
- 在RedHat/CentOS下安装Docker(不升级内核)
- 在RedHat/CentOS下安装Docker(不升级内核)
- 在RedHat/CentOS下安装Docker(不升级内核)
- 在RedHat/CentOS下安装Docker(不升级内核
- Docker的安装,包括内核的升级(centos6内核太低需要升级到3.1以上)
- 通过YUM升级centOS内核,以便安装docker
- 升级centos6.5内核至3.10及安装docker
- linux ECS CentOS 2.6版本内核升级至3.10 安装docker
- 通过YUM升级centOS内核,以便安装docker
- 在centos6.2上安装docker最新的笔记(要升级内核)
- Centos6.5升级内核,并安装docker
- CentOS-6.5在线安装docker-1.7教程(升级内核)
- CentOS-6.5在线安装docker-1.7教程(升级内核)
- Docker的安装,包括内核的升级(centos6内核太低需要升级到3.1以上)
- Centos 6.8升级内核到3.10 安装Docker
- 【Linux】【Docker】CentOs 6.x升级内核到3.10, 安装并升级docker1.9.1
- 在centos和redhat上安装docker
- 一、centos6.6安装Docker 1.7.1 / linux内核2.6升级到3.11.4
- Docker——YUM升级centOS内核(一)