21.04 更新后的 Docker 在 /run/docker.sock 上运行

21.04 更新后的 Docker 在 /run/docker.sock 上运行

将 Ubuntu 从 20.10 更新到 21.04 后,docker 似乎正在运行:

/run/docker.sock

但 docker 客户端会去寻找它:

/var/run/docker.sock

我怎样才能解决这个问题?

详细说明一下,运行 docker 命令我得到:

$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

但docker服务似乎正在另一个位置(在之外)使用docker套接字运行var

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-05-17 10:14:49 CEST; 5s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 10163 (dockerd)
      Tasks: 18
     Memory: 40.5M
     CGroup: /system.slice/docker.service
             └─10163 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.599580310+02:00" level=warning msg="Your kernel does not support CPU realtime scheduler"
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.599624934+02:00" level=warning msg="Your kernel does not support cgroup blkio weight"
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.599642841+02:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.599907138+02:00" level=info msg="Loading containers: start."
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.740160234+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be use>
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.838137738+02:00" level=info msg="Loading containers: done."
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.854381886+02:00" level=info msg="Docker daemon" commit=20.10.2-0ubuntu2 graphdriver(s)=overlay2 version=20.10.2
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.854462072+02:00" level=info msg="Daemon has completed initialization"
may 17 10:14:49 xps-laptop systemd[1]: Started Docker Application Container Engine.
may 17 10:14:49 xps-laptop dockerd[10163]: time="2021-05-17T10:14:49.879020578+02:00" level=info msg="API listen on /run/docker.sock"

编辑(的内容/lib/systemd/system/docker.socket):

$ cat /lib/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

编辑2(的内容/lib/systemd/system/docker.service):

$ cat /lib/systemd/system/docker.service
[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
Wants=containerd.service

[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
TimeoutSec=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.
LimitNOFILE=infinity
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

首先,检查符号链接/var/run是否到位并指向/run(在您的情况下这似乎是没问题的)。

接下来,尝试通过创建 Drop-In 配置来更改“ExecStart”语句:

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/options.conf

现在将以下内容添加到文件/etc/systemd/system/docker.service.d/options.conf

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// --containerd=/run/containerd/containerd.sock

现在重新加载 systemd 配置并重新加载 docker 守护程序:

sudo systemctl daemon-reload
sudo systemctl restart docker

如果您还希望守护进程监听远程端口,请-H tcp://0.0.0.0:2375在“ExecStart”条目中添加/etc/systemd/system/docker.service.d/options.conf

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock

然而,从您的角度来看,改为 似乎就-H unix://起了作用。

答案2

docker.socket如果可以的话,请尝试重新启动服务或重新启动系统:

sudo systemctl restart docker.socket

相关内容