二进制包安装Docker(亲测有效)

二进制包安装Docker

最近公司用docker部署项目,由于是内网环境,安装docker不能yum安装,只能rmp或者二进制包安装,但是rmp安装又有许多的依赖包要安装,而且要解决依赖冲突问题;所以就选择了 二进制安装Docker 方式。网上查了很多资料,踩了很多坑,下面记录本人亲测有效的安装方式、步骤。

一、准备 Docker CE 二进制包

这里使用docker-20.10.21版本。

  1. 下载地址:
    链接: docker-20.10.21.tgz

  2. 服务器下载命令:

wget -c https://download.docker.com/linux/static/stable/x86_64/docker-20.10.21.tgz

二、解压.tgz包

root用户操作:

tar -zxvf docker-20.10.21.tgz 

改变权限:

chown root:root docker/*

三、复制二进制文件到/usr/bin/目录

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

七、启动 dockerd 服务进程

systemctl enable docker.service

八、启动docker服务

systemctl start docker.service

检验是否启动成功

通过运行镜像“hello-world”来验证 Docker Engine 是否正确安装:

sudo docker run hello-world

二进制包安装Docker(亲测有效)_第1张图片

安装完毕!

你可能感兴趣的:(docker,运维,容器)