在CentOS6中安装Docker
背景
由于公司既有多台CentOS6服务器,并且需要在上面继续部署一些其他内部测试服务,为了方便直接安装上Docker。
- Docker官方已不再支持CentOS6
- 如需部署,请部署测试环境,部署线上会有一堆问题
步骤
由于Docker官方已不再支持CentOS6,因此做特定处理
方法一(安装rpm包)
下载官方提供的1.7.1-2版本
yum install -y https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm
此方法虽是官方,但极不稳定,会带来内存泄露与containe和image丢失的问题
方法二(下载预编译文件)
到这 下载地址 获取需要版本(当下载19.03.0及之后的版本,可以将rootless扩展包也下载,尽量不要安装17版本的,会带来内存泄露与containe和image丢失的问题)
根据以下步骤完成替换:
1、Download the static binary archive. Go to https://download.docker.com/linux/static/stable/ (or change stable to nightly or test), choose your hardware platform, and download the .tgz file relating to the version of Docker Engine - Community you want to install.
2、Extract the archive using the tar utility. The dockerd and docker binaries are extracted.
$ tar xvf /path/to/docker-18.09.9.tgz
3、Optional: Move the binaries to a directory on your executable path, such as /usr/bin/. If you skip this step, you must provide the path to the executable when you invoke docker or dockerd commands.
$ sudo cp docker/* /usr/bin/
4、Start the Docker daemon:
$ sudo dockerd &
If you need to start the daemon with additional options, modify the above command accordingly or create and edit the file /etc/docker/daemon.json to add the custom configuration options.
5、Verify that Docker is installed correctly by running the hello-world image.
$ sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
问题
问题一
[root@dev141 src]# INFO[0000] libcontainerd: new containerd process, pid: 29287
WARN[0000] containerd: low RLIMIT_NOFILE changing to max current=1024 max=4096
ERRO[0001] devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a dynamic binary to use devicemapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option
ERRO[0001] [graphdriver] prior storage driver "devicemapper" failed: driver not supported
FATA[0001] Error starting daemon: error initializing graphdriver: driver not supported
由于Docker并不支持Udev同步,Udev在创建和清理期间 和之间会发生竞争导致错误和失败。(有关这些失败的信息,请参阅 docker#4036)
方法一(清除运行文件,当竞争时还是会出错)
#删掉 /var/lib/docker 文件夹
sudo rm -rf /var/lib/docker
#重新启动,问题解决!
sudo dockerd &
方法二(添加启动检测)
# 添加检测,当不支持时自动处理
sudo dockerd --storage-opt dm.override_udev_sync_check=true &
问题二
Devices cgroup isn't mounted
这是cgroup驱动没有加载。
方法:
#安装cgroup
sudo yum install libcgroup
#启动cgroup
sudo service cgconfig start
问题三
Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-d10914bf273f -j RETURN: iptables: No chain/target/match by that name.
导致这错误的原因是:
由于iptables重启过,导致docker对DNAT(目的地址转换)无法跳过或找不到而出错
方法:
service docker restart
# 或者(以下省略了启动的参数,可继续使用自己的启动参数)
sudo dockerd &
问题四
每次卸载加载Docker容器都会发现对外端口无法访问。
这是由于Docker对CentOS6的iptables的支持有限,需要将容器设为restart:always,重启Docker自动配置iptables。