Centos 7 离线安装Docker

Centos 7 离线安装Docker

  1. 下载安装文件

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

image-20220919093815660

  1. 选择自己需要的版本下载并上传到服务器
  2. 安装docker
1
2
3
4
# 解压
tar -zxvf docker-18.06.3-ce.tgz
# 将解压出来的docker文件复制到/usr/bin/目录下
cp docker/* /usr/bin/
  1. 配置docker
1
2
3
4
# 进入/etc/systemd/system/目录
cd /etc/systemd/system/
# 创建docker.service文件
touch docker.service
1
2
# 打开docker.service文件,粘贴以下内容复制
vim 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
[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 --selinux-enabled=false --insecure-registry=0.0.0.0
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. 重新加载配置
1
2
3
4
# docker.service文件添加执行权限
chmod 777 /etc/systemd/system/docker.service
# 重新加载配置文件(每次有修改docker.service文件时都要重新加载下)
systemctl daemon-reload

注意: --insecure-registry=0.0.0.0 此处改为你自己服务器ip

  1. 启动
1
2
3
4
5
6
# 启动
systemctl start docker
# 查看docker状态
systemctl status docker.service
# 设置开机启动
systemctl enable docker.service

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!