CentOS安装Docker

项目需要在一台物理主机部署solrcloud,采用docker进行资源隔离,相对vm更加轻量级。

ubuntu和docker配合的最为默契,centos下面部署相对资源较少,下面是从0开始安装一个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


三、添加hop5.repo源
cd /etc/yum.repos.d 
sudo wget http://www.hop5.in/yum/el6/hop5.repo


四、安装Docker
sudo 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 #挂载单次
vim /etc/fstab,none /cgroup cgroup defaults 0 0 #开机挂载

七、启动docker服务
sudo service docker start # 启动服务 
这里我遇到了一个cgconfig启动失败的日志:
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 or /etc/cgconfig.d[FAILED]
解决方法:cgclear
sudo chkconfig docker on  # 开机启动


八、试运行
sudo docker run -i -t Ubuntu /bin/echo hello world
初次执行此命令会先拉取镜像文件,耗费一定时间。最后应当输出hello world。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值