centos 二进制部署 docker

创建docker组

# groupadd -r docker

安装 docker

下载 docker

# VERSION_STRING=26.1.0
# wget https://download.docker.com/linux/static/stable/x86_64/docker-${VERSION_STRING}.tgz
# tar xf docker-${VERSION_STRING}.tgz

查看 docker 可执行文件

# ls -l docker/
total 194020
-rwxr-xr-x. 1 1000 1000 39182336 Apr 23 01:09 containerd
-rwxr-xr-x. 1 1000 1000 12488704 Apr 23 01:09 containerd-shim-runc-v2
-rwxr-xr-x. 1 1000 1000 19353600 Apr 23 01:09 ctr
-rwxr-xr-x. 1 1000 1000 38400232 Apr 23 01:09 docker
-rwxr-xr-x. 1 1000 1000 71280520 Apr 23 01:09 dockerd
-rwxr-xr-x. 1 1000 1000   708448 Apr 23 01:09 docker-init
-rwxr-xr-x. 1 1000 1000  1979949 Apr 23 01:09 docker-proxy
-rwxr-xr-x. 1 1000 1000 15272168 Apr 23 01:09 runc

复制可执行文件到指定目录

# cp docker/* /usr/bin/
ls -l /usr/bin/{containerd,containerd-shim-runc-v2,ctr,docker,dockerd,docker-init,docker-proxy,runc}

containerd.service

cat >> /lib/systemd/system/containerd.service  << EOF
# 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]
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
EOF

docker.service

cat >> /lib/systemd/system/docker.service  << EOF
[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
EOF

docker.socket

cat >> /lib/systemd/system/docker.socket  << EOF
[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
EOF

设置开机启动

# systemctl enable containerd.service docker.socket docker.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /usr/lib/systemd/system/containerd.service.
Created symlink from /etc/systemd/system/sockets.target.wants/docker.socket to /usr/lib/systemd/system/docker.socket.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

验证docker信息

# docker version
Client:
 Version:           26.1.0
 API version:       1.45
 Go version:        go1.21.9
 Git commit:        9714adc
 Built:             Mon Apr 22 17:05:43 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.9
  Git commit:       c8af8eb
  Built:            Mon Apr 22 17:07:17 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.7.15
  GitCommit:        926c9586fe4a6236699318391cd44976a98e31f1
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

卸载 docker

停止 docker 服务

systemctl stop containerd.service docker.socket docker.service && systemctl disable containerd.service docker.socket docker.service

删除可执行文件

rm -rf /usr/bin/containerd  /usr/bin/containerd-shim-runc-v2  /usr/bin/ctr  /usr/bin/docker  /usr/bin/dockerd  /usr/bin/docker-init  /usr/bin/docker-proxy  /usr/bin/runc

删除数据目录

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

删除配置文件

rm -rf /etc/docker

参考文档

https://docs.docker.com/engine/install/binaries/#/

https://github.com/moby/moby/tree/master/contrib/init/systemd

posted @ 2024-04-25 17:25  小吉猫  阅读(67)  评论(0编辑  收藏  举报