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

docker安装后,使用中经常出现的错误是:

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

Cannot connect to the Docker daemon at (unix:///var/run/docker.sock. Is the docker daemon running?) 
一、什么原因导致的:
触发此错误的一些原因包括:

The Docker daemon is not running.   Docker守护程序未运行。
Docker doesn’t shutdown cleanly.       Docker无法完全关闭。
Lack of root privileges to start the docker service.   缺少启动docker服务的root权限。
              我尝试了第3种方法(启动dockerd)解决了这个问题,所以 分享给大家!

二、各种可能的解决方案。
解决方法1:使用systemctl命令   (Start the Docker service with systemctl)
如果您刚刚在Ubuntu上完成了Docker的新安装或重新启动了PC,那么很有可能Docker服务没有运行( there is a high probability chance the Docker service is not running. )。Docker守护程序(dockerd)是Docker的系统服务。该服务处理各种Docker对象,如图像、容器、网络和卷,并侦听Docker API请求。

Systemctl命令用来取代旧的SysV init系统,它管理在Linux系统上运行的systemd服务。

注意:此方法仅适用于使用APT包管理器安装Docker的用户。如果您通过SNAP安装了Docker,请参阅下面的解决方法5。

(1)在终端中执行 – unmask docker.

sudo systemctl unmask docker
如果docker被masked了,一般会有这样的提示:‘Failed to start docker.service: Unit is masked.’ 

(2)启动 start the docker daemon

systemctl start docker
(3)验证docker是否激活

systemctl status docker
如果出现这的显示,则激活了。

方法2: 清除 ‘Failed Docker Pull’ ,启动 Start Docker service
在某些情况下,您可能会在拉动容器时意外关闭Docker。这种情况将屏蔽docker.service和docker.socket文件。Docker.socket是一个位于“/var/run/Docker.sock”的文件,用于与Docker守护程序通信。在继续启动docker之前,我们需要取消对两个单元文件的屏蔽——docker.service和docker.daemon。(There are cases where you might unexpectedly close Docker while pulling a container. Such situations will mask the docker.service and docker .socket files. Docker.socket is a file located at ‘/var/run/docker.sock’ and is used to communicate with the Docker daemon. We will need to unmask the two-unit files – docker .service and docker.daemon before proceeding to start docker.)

(1)执行命令行:

systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service
执行结果:

如果您在执行下面的命令后仍然遇到错误,我们需要在再次启动Docker之前删除Container目录中的文件。Container是Docker 1.11中引入的一个特性,用于管理Docker映像的生命周期。(If you are still experiencing the error even after executing the commands below, we will need to delete the files in the Containerd directory before starting Docker again. Containerd was a feature introduced in Docker 1.11 and is used to manage Docker images life-cycle.)

(2)提升权限  

命令行:

sudo su
service docker stop
cd /var/run/docker/libcontainerd
rm -rf containerd/*
rm -f docker-containerd.pid
service docker start
.执行结果:

方法 3: 启动Dockerd服务   Start Dockerd (Docker Daemon) Service 
Dockerd是Docker守护程序,它侦听Docker API并管理各种Docker对象。Dockerd可以用作命令“$systemctl start docker”的替代品,该命令也用于启动docker守护程序。(Dockerd is the Docker daemon which listens to Docker APIs and manages the various Docker objects. Dockerd can be used as an alternative to the command ‘$ systemctl start docker‘ which is also used to start the Docker daemon.)

(1)检查  /etc/docker/daemon.json 文件,daemon.json内不能有空格!!!

daemon.json错误的代码:(有空格!)

{
  "registry-mirrors":  [  "https://registry.docker-cn.com"]
}
daemon.json正确的代码:

{"registry-mirrors":["https://registry.docker-cn.com"]}
运行systemctl daemon-reload,service docker start后,启动docker服务。

systemctl daemon-reload
service docker start
(2)使用 dockerd 服务 

sudo dockerd


方法4:如果你服务器使用的是SysV init system(国外的一种系统),使用service command来启动 docker daemon
如果您使用的是SysV init系统,那么systemctl命令将不适用于您。我们需要使用service命令来启动docker守护程序。(If you are using the SysV init system, then the systemctl command will not work for you. We will need to use the service command to start docker daemon.)

命令行为:

sudo service --status-all
sudo service docker start
执行结果为:

方法5:使用snap命令启动(Start the Docker Service with Snap)
如果您使用Snap包管理器安装了Docker,则需要使用Snap命令来管理Docker守护程序。

(If you installed Docker with the Snap package manager, you would need to use the snap command to manage the docker daemon.)

通常,Snap会自动管理其服务。但是,在这种情况下,需要手动干预。可以与snap命令一起使用的一些参数包括stop、start和restart。在本例中,我们将使用start参数。

(Generally, Snap manage their services automatically. However, in situations such as this error, it will require manual intervention. Some of the arguments you can use with the snap command include stop, start, and restart. In our case, we will use the start parameter.)

(1)命令行:

sudo snap start docker
(2)验证

sudo snap services
执行结果:

(3)继续执行命令行

sudo snap connect docker:home :home
sudo snap start docker
方法6:
由于缺乏权限,用户无权访问“unix:///var/run/docker.sock.有一个变通办法。我们将通过端口2375将Docker Host变量导出到localhost。

The error might also arise due to lack of elevated privileges and the user doesn’t have access to ‘unix:///var/run/docker.sock.’ Luckily there is a workaround. We will export the Docker Host variable to the localhost via port 2375.

命令行;

export DOCKER_HOST=tcp://localhost:2375
方法7:重新安装Docker
 如果上述解决方案不能解决错误,则很有可能出现安装错误。要在Linux系统中正确安装Docker,请按照Docker官方网站上的步骤操作。(最后一招了!)
————————————————
版权声明:本文为CSDN博主「weixin_42672605」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42672605/article/details/127748458

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
出现"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"的错误提示,有可能是以下原因导致的。 首先,这个错误提示表明Docker守护程序没有在运行。Docker守护程序是Docker的核心组件,负责处理Docker容器的创建、运行和管理等操作。如果守护程序没有运行,就无法与之进行通信,就会出现这个错误提示。你可以通过检查Docker守护程序是否正在运行来解决这个问题。 其次,可能是Docker守护程序的套接字文件(/var/run/docker.sock)不存在或不可访问。这个套接字文件是Docker守护程序与客户端之间进行通信的通道。如果文件不存在或不可访问,就无法与Docker守护程序建立连接,导致出现这个错误提示。你可以检查该文件是否存在,并确保你有足够的权限来访问它。 另外,可能是Docker守护程序发生了错误或崩溃。在某些情况下,Docker守护程序可能由于各种原因而停止运行,例如配置错误、资源限制或其他操作系统问题。如果守护程序崩溃或停止运行,就无法连接到它,就会出现这个错误提示。你可以检查Docker守护程序的日志文件,以查看是否有任何错误消息或异常情况。 综上所述,出现"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"的错误提示可能是由于Docker守护程序没有运行、套接字文件不存在或不可访问、或Docker守护程序发生了错误或崩溃等原因导致的。你可以按照上述方法逐一排查这些可能的原因,并解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Cannot Connect to the Docker Daemon at ‘unix:///var/run/docker.sock’ 出坑方法,已经解决了](https://blog.csdn.net/weixin_42672605/article/details/127748458)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?](https://blog.csdn.net/qq_58144672/article/details/127974660)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ubuntu vps安装docker报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock....](https://download.csdn.net/download/weixin_38733787/14094320)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值