CentOS安装docker基础教程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS安装docker基础教程相关的知识,希望对你有一定的参考价值。
升级CentOS
准备工作:
1:安装开发平台工具
yum groupinstall "Development tools"
2:安装内核升级需要的依赖组件
yum install ncurses-devel
qt-devel
hmaccalc zlib-devel binutils-devel elfutils-libelf-devel
3:因为selinux和LXC有冲突,所以需要禁用
# vi /etc/selinux/config SELINUX=disabled
4:配置Fedora EPEL 源
,用于yum docker-io
# yum install epel-release.noarch
5:下载升级linux内核源,可以自己去官方下载kernel版本(需要带aufs模块),自己编译。另一种是下载带aufs模块的rpm包(http://down.51cto.com/data/1903250)直接安装(推荐)
升级内核(直接下载的RPM):
gzip -dv kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm.gz
rpm -ivh kernel-ml-aufs-3.10.5-3.el6.x86_64.rpm
设置新的kernel为默认启动项,新安装的内核会在文件列表的第一位,设置为0
vi /etc/grub.cong
default=0
reboot //重启
uname -r //检测当前kernel版本,3.10.5-3.el6.x86_64,则表示升级kernel成功
docker安装主意事项
1:安装docker
yum install docker-io
2:要想docker正常运行还需要在/etc/fstab里增加cgroup文件系统
echo "none /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab
mount /sys/fs/cgroup
只有重新启动才能挂载/sys/fs/cgroup(因为当前运行的内核不支持cgroup),所以上面挂载的命令也可以不执行,但系统需要重新启动
3:检测aufs模块是否加载
grep aufs /proc/filesystems
4:以守护模式运行docker.io(在一个新的终端里)
docker -d
如果出现异常:DNS/Networking Errors inside the docker,可重置docker的运行环境,尝试解决问题
# pkill docker
# iptables -t nat -F
# ifconfig docker0 down
# brctl delbr docker0
# docker -d
5:检测docker是否正常运行
docker run hello-world //默认是不存在这个镜像的,等待docker自动下载hello-world
出现一下信息,则表示docker安装成功
Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Assuming it was not already locally available.) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash For more examples and ideas, visit: http://docs.docker.com/userguide/
异常错误:
1:docker启动的时候报错
Starting cgconfig service: Error: cannot mount cpuset to /cgroupuset: Device or resource busy,(cgconfig 在启动时默认会读取 /etc/cgconfig.config 中的配置来创建 Cgroups 层次结构,绑定所需的文件系统并关联子系统,创建 Cgroups 组并设置每个组的子系统参数)
解决方法:
service cgconfig status //检查是否正常运行
vi /etc/cgconfig.conf
mount {
cpuset = /cgroup/cpuset;
cpu = /cgroup/cpu;
cpuacct = /cgroup/cpuacct;
memory = /cgroup/memory; //注解掉这一段,即:#memory = /cgroup/memory;
devices = /cgroup/devices;
freezer = /cgroup/freezer;
net_cls = /cgroup/net_cls;
blkio = /cgroup/blkio;
}
service cgconfig start //重启开启服务
2:Error response from daemon: Cannot start container {id}: [8] System error: write /sys/fs/cgroup/docker/{id}2a7ce2f9bc/cgroup.procs: no space left on device
处理方法(参考地址:http://stackoverflow.com/questions/29961584/docker-cgroup-procs-no-space-left-on-device):
A simple command should do the trick.
sudo echo 1 > /sys/fs/cgroup/docker/cgroup.clone_children
If it still does not work, run below commands and restart docker service:
sudo echo 0 > /sys/fs/cgroup/docker/cpuset.mems
sudo echo 0 > /sys/fs/cgroup/docker/cpuset.cpus
以上是关于CentOS安装docker基础教程的主要内容,如果未能解决你的问题,请参考以下文章
CentOS下使用Docker安装Jenkins及配置详细教程
docker配置centos7的python2.7下scrapy基础环境遇到的问题