选择二进制文件安装方式原因:内网无网络,可事先下好包,传到内网进行安装

卸载老版本,执行命令,如下

sudo dnf remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-engine \
                podman \
                runc

安装 Docker Engine 二进制安装包,参考链接,我下载 x86_64 版本 docker-28.4.0.tgz,其他平台自行选择版本

新建 /opt/docker-temp 用来存储上传包(注意新建目录权限,所有安装完成后目录可删除),执行命令,如下

sudo mkdir /opt/docker-temp
sudo chown -R $USER:$USER /opt/docker-temp
cd /opt/docker-temp

docker-28.4.0.tgz 上传到 /opt/docker-temp 后,解压,复制解压后的文件至 /usr/bin/,执行命令,如下

tar xzvf /opt/docker-temp/docker-28.4.0.tgz
sudo cp docker/* /usr/bin/

启动 Docker,执行命令,如下

sudo dockerd &

ctrl + c 停止 dockerd 进程

创建 docker 组,将当前用户加入到 docker 用户组,执行命令,如下

sudo groupadd docker
sudo usermod -aG docker $USER
sudo newgrp docker

将 Docker 服务注册到 systemd,在 /lib/systemd/system/ 目录新建 containerd.service docker.service docker.socket 三个文件,如下

sudo vim /lib/systemd/system/containerd.service

# Copyright The containerd Authors.

#

# Licensed under the Apache License, Version 2.0 (the "License");

# you may not use this file except in compliance with the License.

# You may obtain a copy of the License at

#

#     http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

[Unit]

Description=containerd container runtime

Documentation=https://containerd.io

After=network.target local-fs.target

[Service]

#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration

#Environment="ENABLE_CRI_SANDBOXES=sandboxed"

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 vim /lib/systemd/system/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 --default-ulimit nofile=65536:65536 -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

sudo vim /lib/systemd/system/docker.socket

[Unit]
Description=Docker Socket for the API

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

注册服务,执行命令,如下

sudo systemctl enable containerd.service
sudo systemctl enable docker.service
sudo systemctl enable docker.socket
sudo systemctl daemon-reload
sudo systemctl start docker.service

安装 Docker Compose 插件,参考链接,我下载 v2.39.3 版本 docker-compose-linux-x86_64,其他平台自行选择版本

docker-compose-linux-x86_64 上传到 /opt/docker-temp 后,复制并重命名至 /usr/local/lib/docker/cli-plugins/docker-compose,再添加执行权限,执行命令,如下

sudo mkdir -p /usr/local/lib/docker/cli-plugins/
sudo cp /opt/docker-temp/docker-compose-linux-x86_64 /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose