离线安装docker

CentOS版本:7.9

docker版本:20.10.1

  • 下载docker离线安装包
1
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.1.tgz
  • 解压安装包
1
tar -zxvf docker-20.10.1.tgz
  • 将二进制文件移动到指定位置 /usr/local/bin
1
mv docker/* /usr/local/bin
  • 建立docker数据存放目录 /data/docker/data/docker
1
mkdir -p /data/docker
  • 创建 docker 服务
1
vim /usr/lib/systemd/system/docker.service
  • 编辑docker.service,写入以下内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[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/local/bin/dockerd --data-root /data/docker

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
  • 重新加载配置
1
systemctl daemon-reload

启动

  • 启动docker服务
1
systemctl start docker
  • 设置开机自启动
1
systemctl enable docker

脚本

1
2
3
4
5
6
7
8
9
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.1.tgz
tar -zxvf docker-20.10.1.tgz
mv docker/* /usr/local/bin
mkdir -p /data/docker


systemctl daemon-reload
systemctl restart docker
systemctl enable docker

安装docker-compose