此处示例 Docker 二进制文件目录为
/opt/docker/bin
、Docker 数据目录为/opt/docker/data
,实际请按需修改
mkdir -pv /opt/docker/{bin,data}
mkdir -pv /etc/docker
groupadd -r -g 1001 docker
useradd -r -g docker -u 1001 -d /home/docker -s /bin/bash docker
modprobe br_netfilter
echo 'net.bridge.bridge-nf-call-ip6tables = 1' > /etc/sysctl.d/docker.conf
echo 'net.bridge.bridge-nf-call-iptables = 1' >> /etc/sysctl.d/docker.conf
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.d/docker.conf
sysctl --system
下载地址:
示例如下:
wget https://download.docker.com/linux/static/stable/x86_64/docker-27.0.3.tgz
解压上一步中下载的二进制包到自定义目录(此处将文件解压到 /opt/docker/bin
目录)
tar zxvf docker-27.0.3.tgz -C /opt/docker/bin --strip-components 1
解压后文件夹中包含的文件如下:
-rwxr-xr-x 1 1000 1000 38995448 Oct 26 02:03 containerd
-rwxr-xr-x 1 1000 1000 7446528 Oct 26 02:03 containerd-shim
-rwxr-xr-x 1 1000 1000 9646080 Oct 26 02:03 containerd-shim-runc-v2
-rwxr-xr-x 1 1000 1000 20750336 Oct 26 02:03 ctr
-rwxr-xr-x 1 1000 1000 48047088 Oct 26 02:03 docker
-rwxr-xr-x 1 1000 1000 57789848 Oct 26 02:03 dockerd
-rwxr-xr-x 1 1000 1000 765808 Oct 26 02:03 docker-init
-rwxr-xr-x 1 1000 1000 2555160 Oct 26 02:03 docker-proxy
-rwxr-xr-x 1 1000 1000 13847864 Oct 26 02:03 runc
vim ~/.bashrc
# Docker Env Begin
export DOCKER_HOME=/opt/docker/bin
export PATH=$PATH:$DOCKER_HOME
# Docker Env End
source ~/.bashrc
vim /etc/profile
# Docker Env Begin
export DOCKER_HOME=/opt/docker/bin
export PATH=$PATH:$DOCKER_HOME
# Docker Env End
source /etc/profile
其中
/opt/docker/bin
为 Docker 可执行文件目录
vim /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
Requires=docker.socket
[Service]
Type=notify
Environment=PATH=/opt/docker/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 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=/opt/docker/bin/dockerd -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP
# 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
其中
/opt/docker/bin
为 Docker 可执行文件目录
vim /lib/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
如不存在
/etc/docker
目录,则需要先新建目录
vim /etc/docker/daemon.json
{
"exec-opts" : ["native.cgroupdriver=systemd"],
"log-level": "warn",
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
},
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com",
"https://m.daocloud.io"
],
"bip": "10.21.21.1/24",
"data-root": "/opt/docker/data",
"live-restore": true
}
/opt/docker/data
为 Docker 数据目录,后续镜像、存储卷等均会保存到此目录,因此需要确保有足够的空间
10.21.21.1/24
为 Docker 容器使用的网段,注意不能和服务器的网段冲突
chmod -R docker.docker /opt/docker
chmod -R 755 /opt/docker
systemctl daemon-reload
systemctl start docker
systemctl enable docker
docker version
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | grep "^doc" | sort -r
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
yum install -y docker-ce-版本号 docker-ce-cli-版本号 containerd.io docker-buildx-plugin docker-compose-plugin
示例(安装 26.1.2
版本):
yum install -y docker-ce-26.1.2-1.el7 docker-ce-cli-26.1.2-1.el7 containerd.io docker-buildx-plugin docker-compose-plugin
如不存在
/etc/docker
目录,则需要先新建目录
vim /etc/docker/daemon.json
{
"exec-opts" : ["native.cgroupdriver=systemd"],
"log-level": "warn",
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
},
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com"
],
"bip": "10.21.21.1/24",
"data-root": "/opt/docker/data",
"live-restore": true
}
/opt/docker/data
为 Docker 数据目录,后续镜像、存储卷等均会保存到此目录,因此需要确保有足够的空间
10.21.21.1/24
为 Docker 容器使用的网段,注意不能和服务器的网段冲突
systemctl enable docker
systemctl start docker
docker version
docker info
/usr/bin
/etc/docker
/var/lib/docker
zypper search -xs docker
zypper install -y docker=版本号
示例:
zypper install -y docker
zypper install -y docker=20.10.23_ce-150000.175.1
如不存在
/etc/docker
目录,则需要先新建目录
vim /etc/docker/daemon.json
{
"exec-opts" : ["native.cgroupdriver=systemd"],
"log-level": "warn",
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
},
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com"
],
"bip": "10.21.21.1/24",
"data-root": "/opt/docker/data",
"live-restore": true
}
/opt/docker/data
为 Docker 数据目录,后续镜像、存储卷等均会保存到此目录,因此需要确保有足够的空间
10.21.21.1/24
为 Docker 容器使用的网段,注意不能和服务器的网段冲突
systemctl enable docker
systemctl start docker
docker version
docker info
/usr/bin
/etc/docker
/var/lib/docker
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
apt-cache madison docker-ce | awk '{ print $3 }'
返回示例:
5:27.0.3-1~ubuntu.22.04~jammy
5:27.0.2-1~ubuntu.22.04~jammy
5:27.0.1-1~ubuntu.22.04~jammy
5:26.1.4-1~ubuntu.22.04~jammy
5:26.1.3-1~ubuntu.22.04~jammy
5:26.1.2-1~ubuntu.22.04~jammy
5:26.1.1-1~ubuntu.22.04~jammy
5:26.1.0-1~ubuntu.22.04~jammy
5:26.0.2-1~ubuntu.22.04~jammy
5:26.0.1-1~ubuntu.22.04~jammy
5:26.0.0-1~ubuntu.22.04~jammy
5:25.0.5-1~ubuntu.22.04~jammy
5:25.0.4-1~ubuntu.22.04~jammy
5:25.0.3-1~ubuntu.22.04~jammy
5:25.0.2-1~ubuntu.22.04~jammy
5:25.0.1-1~ubuntu.22.04~jammy
5:25.0.0-1~ubuntu.22.04~jammy
5:24.0.9-1~ubuntu.22.04~jammy
5:24.0.8-1~ubuntu.22.04~jammy
5:24.0.7-1~ubuntu.22.04~jammy
5:24.0.6-1~ubuntu.22.04~jammy
5:24.0.5-1~ubuntu.22.04~jammy
5:24.0.4-1~ubuntu.22.04~jammy
5:24.0.3-1~ubuntu.22.04~jammy
5:24.0.2-1~ubuntu.22.04~jammy
5:24.0.1-1~ubuntu.22.04~jammy
5:24.0.0-1~ubuntu.22.04~jammy
5:23.0.6-1~ubuntu.22.04~jammy
5:23.0.5-1~ubuntu.22.04~jammy
5:23.0.4-1~ubuntu.22.04~jammy
5:23.0.3-1~ubuntu.22.04~jammy
5:23.0.2-1~ubuntu.22.04~jammy
5:23.0.1-1~ubuntu.22.04~jammy
5:23.0.0-1~ubuntu.22.04~jammy
5:20.10.24~3-0~ubuntu-jammy
5:20.10.23~3-0~ubuntu-jammy
5:20.10.22~3-0~ubuntu-jammy
5:20.10.21~3-0~ubuntu-jammy
5:20.10.20~3-0~ubuntu-jammy
5:20.10.19~3-0~ubuntu-jammy
5:20.10.18~3-0~ubuntu-jammy
5:20.10.17~3-0~ubuntu-jammy
5:20.10.16~3-0~ubuntu-jammy
5:20.10.15~3-0~ubuntu-jammy
5:20.10.14~3-0~ubuntu-jammy
5:20.10.13~3-0~ubuntu-jammy
VERSION_STRING=5:27.0.3-1~ubuntu.22.04~jammy
此处
5:27.0.3-1~ubuntu.22.04~jammy
为需要安装的版本,按需要替换即可
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
如不存在
/etc/docker
目录,则需要先新建目录
vim /etc/docker/daemon.json
{
"exec-opts" : ["native.cgroupdriver=systemd"],
"log-level": "warn",
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
},
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com"
],
"bip": "10.21.21.1/24",
"data-root": "/opt/docker/data",
"live-restore": true
}
/opt/docker/data
为 Docker 数据目录,后续镜像、存储卷等均会保存到此目录,因此需要确保有足够的空间
10.21.21.1/24
为 Docker 容器使用的网段,注意不能和服务器的网段冲突
systemctl enable docker
systemctl start docker
docker version
docker info
/usr/bin
/etc/docker
/var/lib/docker