Offline Installation Of Docker CE On RHEL 7.4

记录在RHEL 7.4离线环境下安装Docker CE以及遇到一些问题和解决方案

首先需要确保一件事情,Linux kernel的版本不能过低,Thank GOD,我这边的Kernel 是 3.10. 首先获取一下Docker CE的binary包你可以在以下连接下载到

https://download.docker.com/linux/static/stable/x86_64/

获取到包之后我们将其解压之后,将docker文件夹中所有二进制文件mv 到 /usr/bin 目录下

编写docker.service 文件 如下:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target

将改service文件放置目录/etc/systemd/system/ 下 并执行 systemctl daemon-reload

创建docker组 使用该命令: sudo groupadd docker 如果遇到groupadd :can not open /etc/gshadow 错误,我们可以使用chattr -i /etc/gshadow; chattr -i /etc/group 进行解决。如果我们有需求让非root用户使用docker,我们可以将普通用户放到docker组内,使用sudo gpasswd -a myUserName docker 操作完之后重启docker并执行newgrp – docker 之后,myUserName用户就可以正常使用docker了

systemctl start docker 无效且journalctl -xe 查看到错误: error while opening volume store metadata database: timeout的时候使用以下shell 命令彻底查杀残余进程 再次重启docker 即可

ps axf | grep docker | grep -v grep | awk ‘{print “kill -9 ” $1}’ | sudo sh

最后写个小贴士: 在exec container的时候如果要传入命令带多参数的时候可以使用 -c 加 “” 来使用。 e.g