二进制安装docker并设置为服务

使用麒麟操作系统,默认的Docker为18.0.9版本,本想通过Docker官方添加yum源的方式安装新版的docker,但是操作系统依赖不满足,各种包都被改名ky10,所以考虑二进制直接安装。
Docker二进制包下载地址,本人下载的24.0.5版本

安装Docker

tar -xzvf docker-24.0.5.tgz
cp ./docker/* /usr/bin

此时执行dockerd启动Docker可以成功启动后台服务,其实到这里已经够用,只要让dockerd运行在后台即可,但是配置成systemd服务会更好些。

配置systemd服务

需要生成两个文件/etc/systemd/system

  1. docker.service,修改ExecStart如下所示
[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
# 此处修改
ExecStart=/usr/bin/dockerd
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
  1. 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

更改配置,并设置自启动

chmod 755 ./docker.service ./docker.socket
systemctl daemon-reload
systemctl start docker
systemctl enable docker

测试是否成功

[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-08-28 19:05:42 CST; 59s ago
     Docs: https://docs.docker.com
 Main PID: 4423 (dockerd)
    Tasks: 22
   Memory: 146.4M
   CGroup: /system.slice/docker.service
           ├─4423 /usr/bin/dockerd
           └─4499 containerd --config /var/run/docker/containerd/containerd.toml

docker run hello-world在银河麒麟V10上报permission denied错误,有以下解决办法。

  1. docker run添加–privileged=true参数,每个容器都要添加,很麻烦。
  2. 卸载podman,银河麒麟自带的和selinux,containerd有关的包。
yum autoremove podman
systemctl restart docker

Q.E.D.


一切很好,不缺烦恼。