最近公司用docker部署项目,由于是内网环境,安装docker不能yum安装,只能rmp或者二进制包安装,但是rmp安装又有许多的依赖包要安装,而且要解决依赖冲突问题;所以就选择了 二进制安装Docker 方式。网上查了很多资料,踩了很多坑,下面记录本人亲测有效的安装方式、步骤。
这里使用docker-20.10.21版本。
下载地址:
链接: docker-20.10.21.tgz
服务器下载命令:
wget -c https://download.docker.com/linux/static/stable/x86_64/docker-20.10.21.tgz
root用户操作:
tar -zxvf docker-20.10.21.tgz
改变权限:
chown root:root docker/*
cp -p docker/* /usr/bin/
groupadd docker
有三个配置文件:docker.service 、docker.socket、 containerd.service。
docker.service配置文件:
touch docker.service
vim 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
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
docker.socket配置文件:
touch docker.socket
vim docker.socket
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
containerd.service配置文件:
touch containerd.service
vim containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
sudo cp docker.socket /etc/systemd/system
sudo cp docker.service /etc/systemd/system
sudo cp containerd.service /etc/systemd/system
添加可执行权限:
chmod a+x /etc/systemd/system/docker.service
chmod a+x /etc/systemd/system/docker.socket
chmod a+x /etc/systemd/system/containerd.service
systemctl enable docker.service
systemctl start docker.service
通过运行镜像“hello-world”来验证 Docker Engine 是否正确安装:
sudo docker run hello-world