执行docker命令时异常: at unix:///var/run/docker.sock. Is the docker daemon running

生活中,最使人疲惫的往往不是道路的遥远,而是心中的郁闷;最使人痛苦的往往不是生活的不幸,而是希望的破灭;最使人颓废的往往不是前途的坎坷,而是自信的丧失;最使人绝望的往往不是挫折的打击,而是心灵的死亡。所以我们要有自己的梦想,让梦想的星光指引着我们走出落漠,走出惆怅,带着我们走进自己的理想。

导读:本篇文章讲解 执行docker命令时异常: at unix:///var/run/docker.sock. Is the docker daemon running,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

场景

执行docker ps命令时发现异常:

[root@administrator yum.repos.d]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running

执行如下常规操作均无解:

1.重启Docker:systemctl restart docker

2.停止Docker:systemctl stop docker

3.启动Docker:systemctl start docker

原因分析

首先:daemon默认监听/var/run/docker.sock这个文件,docker客户端把请求发往这里,daemon就能收到并做出响应。

其次:看异常信息推测:var/run/docker.sock文件异常,执行systemctl status docker.socket查看其状态

[root@administrator yum.repos.d]# systemctl status docker.socket
● docker.socket - Docker Socket for the API
   Loaded: loaded (/usr/lib/systemd/system/docker.socket; enabled; vendor preset: disabled)
   Active: failed (Result: resources) since 三 2022-06-15 23:36:57 CST; 52s ago
   Listen: /var/run/docker.sock (Stream)

615 23:36:57 administrator systemd[1]: Closed Docker Socket for the API.
615 23:37:20 administrator systemd[1]: docker.socket failed to listen on sockets: Address already in use
615 23:37:20 administrator systemd[1]: Failed to listen on Docker Socket for the API.
615 23:37:20 administrator systemd[1]: Unit docker.socket entered failed state.
615 23:37:36 administrator systemd[1]: docker.socket failed to listen on sockets: Address already in use
615 23:37:36 administrator systemd[1]: Failed to listen on Docker Socket for the API.
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
[root@administrator yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since 三 2022-06-15 23:36:57 CST; 1min 7s ago
     Docs: https://docs.docker.com
  Process: 6895 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=0/SUCCESS)
 Main PID: 6895 (code=exited, status=0/SUCCESS)

执行ls -l /var/run/ | grep docker 命令,发现docker.sock是一个目录,正常来说应该是一个文件。

[root@administrator yum.repos.d]# ls -l /var/run/ | grep docker
drwx------  8 root   root    160 615 23:36 docker
drwxr-xr-x  2 root   root     40 68 01:07 docker.sock

解决方案

执行rm -rf /var/run/docker.sock命令将其删除

[root@administrator yum.repos.d]# rm -rf /var/run/docker.sock

重启docker容器后发现其正常

[root@administrator yum.repos.d]# systemctl start docker
[root@administrator yum.repos.d]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED        STATUS         PORTS                    NAMES
02688799076d   portainer/portainer      "/portainer"             6 months ago   Up 4 seconds   0.0.0.0:9000->9000/tcp   portainer

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/136943.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!