离线安装docker

1.软件环境

软件 版本
centos 7.6
docker 19

2.下载docker安装包

官方地址:https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz

3.解压缩

1
tar -zxvf docker-19.03.9.tgz

4.解压的docker文件夹全部移动至/usr/bin目录

1
cp -p docker/* /usr/bin

5.将docker注册为系统服务

创建并编辑docker.service文件

1
vi /usr/lib/systemd/system/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
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
[Service]
Type=notify
EnvironmentFile=-/run/flannel/docker
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/dockerd \
-H tcp://0.0.0.0:4243 \
-H unix:///var/run/docker.sock \
--selinux-enabled=false \
--log-opt max-size=1g
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=on-failure
[Install]
WantedBy=multi-user.target

6.配置日志文件最大大小和镜像下载地址

1
2
3
4
5
6
more /etc/docker/daemon.json
{
"registry-mirrors": ["https://hmp3678i.mirror.aliyuncs.com"],"insecure-registries": ["172.31.10.118"],
"log-driver":"json-file",
"log-opts": {"max-size":"100m", "max-file":"3"}
}

7.重启生效

重启守护进程

1
2
3
4
5
6
7
8
9
systemctl daemon-reload

systemctl start docker

systemctl status docker
#设置开机启动
systemctl enable docker

docker version