Docker 二进制安装
适用于国产操作系统(UOS、Anolis OS、Kylin等)安装Docker
准备工作
-
已经安装好的操作系统(OS)
-
上传已经下载好docker安装文件
下载二进制安装包
下载地址(请根据机器的架构和自身版本要求选择下载的二进制安装包,我安装的是x86_64): docker-binary-install-package-downloads
安装
解压
tar xf docker-26.1.0.tgz
解压后会有一个 docker
文件夹
拷贝文件到启动路径
cp docker/* /usr/bin/
准备容器(container)service文件
cat >/etc/systemd/system/containerd.service <<EOF
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=1048576
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF
设置开机自启
systemctl enable --now containerd.service
准备docker的service启动文件
cat > /etc/systemd/system/docker.service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
EOF
准备docker的socket文件
cat > /etc/systemd/system/docker.socket <<EOF
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF
启动
创建docker组
groupadd docker
启动docker socket 并设设置开机自启
systemctl enable --now docker.socket && systemctl enable --now docker.service
查看docker信息(此步可以验证docker是否安装安装成功)
docker info
- 如果可以查看到docker的详细信息就是安装成功了,或者使用
docker -v
查看到docker的版本也是可以的
docker 配置
# 创建docker配置文件目录及文件
mkdir -p /etc/docker
touch /etc/docker/daemon.json
# 添加配置信息
cat >/etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"max-concurrent-downloads": 10,
"log-driver": "json-file",
"log-level": "warn",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"data-root": "/var/lib/docker"
}
EOF
重启docker
systemctl restart docker
完结撒花!!!