docker命令无法连接到后台进程
docker配置/etc/config/daemon.json
中disable-legacy-registry
导致docker无法启动。
该配置选项的含义是“是否允许访问旧版镜像仓库”。
问题描述
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
排查方案
检查docker服务运行状态
root@ubuntu24:/home/blduan# sudo systemctl status docker
× docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Mon 2024-12-30 10:52:25 CST; 1 day 3h ago
TriggeredBy: × docker.socket
Docs: https://docs.docker.com
Process: 1582 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 1582 (code=exited, status=1/FAILURE)
CPU: 35ms
Dec 30 10:52:25 ubuntu24 systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Dec 30 10:52:25 ubuntu24 systemd[1]: docker.service: Start request repeated too quickly.
Dec 30 10:52:25 ubuntu24 systemd[1]: docker.service: Failed with result 'exit-code'.
Dec 30 10:52:25 ubuntu24 systemd[1]: Failed to start docker.service - Docker Application Container Engine.
结果显示docker未启动,解决方案启动docker:sudo systemctl start docker
root@ubuntu24:/home/blduan# sudo systemctl start docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xeu docker.service" for details.
docker启动失败,查看日志
░░ The job identifier is 3056 and the job result is failed.
Dec 31 14:41:26 ubuntu24 systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ Automatic restarting of the unit docker.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Dec 31 14:41:26 ubuntu24 systemd[1]: docker.service: Start request repeated too quickly.
Dec 31 14:41:26 ubuntu24 systemd[1]: docker.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit docker.service has entered the 'failed' state with result 'exit-code'.
Dec 31 14:41:26 ubuntu24 systemd[1]: Failed to start docker.service - Docker Application Container Engine.
░░ Subject: A start job for unit docker.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit docker.service has finished with a failure.
░░
░░ The job identifier is 3161 and the job result is failed.
检查docker配置
blduan@ubuntu24:~$ sudo dockerd --config-file /etc/docker/daemon.json --validate
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: disable-legacy-registry
可以看到配置出错,删除/etc/config/daemon.json
中的配置disable-legacy-registry
行。
重新检测docker配置:
blduan@ubuntu24:~$ sudo dockerd --config-file /etc/docker/daemon.json --validate
configuration OK
重新加载docker配置并重启
blduan@ubuntu24:~$ sudo systemctl daemon-reload
blduan@ubuntu24:~$ sudo systemctl restart docker
blduan@ubuntu24:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)
Active: active (running) since Tue 2024-12-31 15:03:49 CST; 5s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 2800 (dockerd)
Tasks: 13
Memory: 39.1M (peak: 40.8M)
CPU: 383ms
CGroup: /system.slice/docker.service
└─2800 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Dec 31 15:03:48 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:48.938059131+08:00" level=info msg="Removing stale sandbox 2a3c83df4135cbcf0a6829724b30e1c66a13766ea433524f052105be1f94b389 (>Dec 31 15:03:48 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:48.941471403+08:00" level=warning msg="Error (Unable to complete atomic operation, key modified) deleting object [endpoint 9a>Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.109338028+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bi>Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.208242872+08:00" level=warning msg="error locating sandbox id 5a6fe1a3bc3d795e26c926efaad9b6e6cf04c418f06ed71eaacb27df4480>Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.208301913+08:00" level=warning msg="error locating sandbox id 2a3c83df4135cbcf0a6829724b30e1c66a13766ea433524f052105be1f94>Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.208474428+08:00" level=info msg="Loading containers: done."
Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.235683600+08:00" level=info msg="Docker daemon" commit=c710b88 containerd-snapshotter=false storage-driver=overlay2 versio>Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.244400289+08:00" level=info msg="Daemon has completed initialization"
Dec 31 15:03:49 ubuntu24 dockerd[2800]: time="2024-12-31T15:03:49.333404076+08:00" level=info msg="API listen on /run/docker.sock"
Dec 31 15:03:49 ubuntu24 systemd[1]: Started docker.service - Docker Application Container Engine.
- 原文作者:生如夏花
- 原文链接:https://blduan.top/post/%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5/docker%E5%91%BD%E4%BB%A4%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E5%88%B0%E5%90%8E%E5%8F%B0%E8%BF%9B%E7%A8%8B/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。