离线安装 Docker 环境

离线包下载:https://download.docker.com/linux/static/stable/x86_64/

1、解压

tar zxvf docker-27.2.0.tgz

2、进入解压目录

cd docker

3、复制文件到系统目录(如有文件替换提示,可以选择跳过不替换)

cp * /usr/bin

4、建立 docker 服务文件

vi /etc/systemd/system/docker.service

可以从其它已安装 docker 的系统中复制内容过来: cat /usr/lib/systemd/system/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 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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

另一个模板:https://github.com/moby/moby/blob/master/contrib/init/systemd/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

将以上内容复制到 /etc/systemd/system/docker.service 文件中,保存退出。

5、为 docker.service 增加可执行权限:

chmod +x /etc/systemd/system/docker.service

6、后续就跟正常安装一样了,重启 docker 服务

systemctl daemon-reload
systemctl restart docker

7、设置开机启动

systemctl enable docker

8、查看docker状态

systemctl status docker

参考:https://blog.csdn.net/DeliaPu/article/details/120361534

https://blog.csdn.net/chexlong/article/details/127932711

posted @ 2024-08-28 18:53  不是豆豆  阅读(27)  评论(0编辑  收藏  举报
友情链接:迷途