Cannot Connect to the Docker Daemon at ‘unix:///var/run/docker.sock’ 出坑方法,已经解决了_cannot connect to the docker daemon at unix:///var-程序员宅基地

技术标签: ubuntu  unix  docker  

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官方网站上的步骤操作。(最后一招了!)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42672605/article/details/127748458

智能推荐

使用iframe搭建微前端_iframe框架搭建解析-程序员宅基地

文章浏览阅读1.4k次。var ISPA = function(options){ var _this = this this.callback = options.callback || new Function this.hash this.prefix = options.prefix || '' this.anchor = o..._iframe框架搭建解析

POI中设置Excel单元格格式样式(居中,字体,边框等)_poi居中-程序员宅基地

文章浏览阅读10w+次,点赞13次,收藏29次。【代码】POI中设置Excel单元格格式样式(居中,字体,边框等)_poi居中

SpringBoot之ActiveMQ实现延迟消息_activemq 如何在控制面板创建延时消息topic-程序员宅基地

文章浏览阅读723次。【北京】 IT技术人员面对面试、跳槽、升职等问题,如何快速成长,获得大厂入门资格和升职加薪的筹码?与大厂技术大牛面对面交流,解答你的疑惑。《从职场小白到技术总监成长之路:我的职场焦虑与救赎》活动链接:码客 恭喜fpx,新王登基,lpl*b 我们是冠军一、安装activeMQ​ 安装步骤参照网上教程,本文不做介绍二、修改activeMQ配置文件​ broker新增配置信息 sch..._activemq 如何在控制面板创建延时消息topic

Tessent scan & ATPG (1)scan chain基本原理_tessent lpct-程序员宅基地

文章浏览阅读1.6w次,点赞27次,收藏193次。从制造缺陷开始,介绍scan chain的基本原理_tessent lpct

创建DOTA2本地数据库(一)-程序员宅基地

文章浏览阅读222次。在APP中,用本地数据库好于频繁的联网去获取相关数据。我使用SQLite作为本地的数据库,比较轻巧。英雄首先先建立英雄的数据库,暂时我先只设置ID,name,loaclized_name这三种,我这是在窗体应用程序里写的,不要在意那些细节,其实我们只是要先创建这么一个.db文件 public Form1() { I...

响应式编程库Reactor 3 Reference Guide参考文档中文版(v3.2.0)-程序员宅基地

文章浏览阅读231次。Project Reactor 是 Spring WebFlux 的御用响应式编程库,与 Spring 是兄弟项目。关于如何基于Spring的组件进行响应式应用的开发,欢迎阅读系列文章《响应式Spring的道法术器》。官方参考文档地址:http://projectreactor.io/docs/core/release/reference/中文翻译文档地址:http://htmlprevi..._reactor 指南中文版v3.0

随便推点

剑指offer(十五):字典序全排列_数组最小字典序是什么意思-程序员宅基地

文章浏览阅读329次。题目描述输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。分析字典序算法解析:最小字典序是数组从小到大的排序,最大字典序是最小字典序的倒序。找到下一个字典序的步骤如下:1)定义一个指针指向数组的最后一个数,从右向左找到第一个小于自己的右侧相邻元素的元素ai,以ai..._数组最小字典序是什么意思

Vuforia核心特征视频教程_unity3d vuforia 教程视频-程序员宅基地

文章浏览阅读778次。播单传送门:http://list.youku.com/albumlist/show/id_49507134.html?spm=a2h0j.8191423.module_basic_info.5~5~8~A这是本人制作的vuforia初级视频,供大家一起学习交流。本视频主要介绍vuforia的主要特征和演示使用官方的预制体创建案例。主要内容如下:一Vuforia简介及安装步骤二文字识别1...._unity3d vuforia 教程视频

MQTT协议的智能家居之窗帘机器人与空调_家用空调有mqtt协议通讯吗?-程序员宅基地

文章浏览阅读639次。继之前的文章 《用自己的mqtt服务器实现家居控制和监测》后续,到此为止算是完成了我整个毕业设计,实现对家居数据的采集功能、对家中空调、电视、窗帘、灯的App控制、Web控制、语音识别控制以及天猫精灵等智能语音设备接入控制。先演示下视频吧,由于外壳制作暂时只完成了窗帘机器人制作,本视频只演示窗帘控制。 窗帘机器人 _家用空调有mqtt协议通讯吗?

pymongo update_one执行成功返回值_手把手教你如何使用Python执行js代码-程序员宅基地

文章浏览阅读1.4k次。为什么要引出Python执行js这个问题?都说术业有专攻,每个语言也都有自己的长处和短处。在爬虫方向,Python绝对是扛把子,近几年随着AI的火爆,需要各种各样的数据,所以,爬虫需求也跟着水涨船高起来。我们做爬虫的当然是爬的爽,但是估计人家后台在骂街,毕竟谁都不希望自己的数据被弄走,所以后台反爬技术也在快速提升,一攻一防就这么在拉锯着。现在为了防止反爬,前端使用的反爬技术比较多的是js代码混淆。..._update_one 返回值 pymongo

Config配置搜索路径_configservices路径-程序员宅基地

文章浏览阅读812次。前面所有的GIT远程端配置文件都放在是根目录的,所有请求默认都是根目录,但是有时候,项目很多,配置文件需要根据子目录来划分,这时候,就需要来配置搜索路径了;比如aaa项目的配置文件放aaa目录下,bbb项目的配置文件放bbb目录下,不配置的话是找不到的那些配置文件的,需要配置search-paths属性来实现在microservice-config-server-4001项目的yml文件加个配..._configservices路径

c++笔记-程序员宅基地

文章浏览阅读62次。多行代码的函数:std::cout << R"()";