GVKun编程网logo

Ubuntu 18.04下Couldn't connect to Docker daemon at http+docker://localunixsocket解决办法

1

在本文中,我们将带你了解Ubuntu18.04下Couldn'tconnecttoDockerdaemonathttp+docker://localunixsocket解决办法在这篇文章中,同时我们还

在本文中,我们将带你了解Ubuntu 18.04下Couldn't connect to Docker daemon at http+docker://localunixsocket解决办法在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的Cannot connect to the Docker daemon at tcp://xxx.xx.x.x:2376. Is the docker daemon running?、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? 解决、Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?错误

本文目录一览:

Ubuntu 18.04下Couldn't connect to Docker daemon at http+docker://localunixsocket解决办法

Ubuntu 18.04下Couldn't connect to Docker daemon at http+docker://localunixsocket解决办法

  一台服务器系统为:Ubuntu 18.04 LTS,上面建了git裸仓库,用于开发吧代码push到这里。同时WEB测试环境通过docker也部署在这台。通过git钩子post-receive,当有新代码提交是,就自动将最新的代码checkout到web测试目录,然后在手动重启容器,让java程序生效。由于代码更新频繁,手动重启太麻烦,就在git钩子post-receive脚本里增加了docker-compose restart的代码,然后提交代码是就会出现下面的错误:

remote: Couldn‘t connect to Docker daemon at http+docker://localunixsocket - isit running?
remote: If it‘s at a non-standard location,specify the URL with the DOCKER_HOST environment variable.

 post-receive的脚本如下:

#!/bin/sh
WEBDIR=/data/webroot
/usr/bin/git --work-tree=${WEBDIR} clean -fd
/usr/bin/git --work-tree=${WEBDIR} checkout --force
#sudo chown -R www:www ${WEBDIR}
/usr/bin/docker-compose -f /docker-tomcat/docker-compose.yml restart

初看那个错误是提示docker-compose连不上docker daemon,连接docker daemon有两种方式,一种是通过TCP协议,一种是通过unixsocket。docker默认是通过unixsocket来通信的。

我在/var/run目录下找到了docker.sock文件:

原来这个文件的只有root用户和docker组用户可以访问,而我的git钩子是在git账号下运行的,于是:

usermod -aG docker git

把git用户加入到docker组,再次提交更行代码,容器可以自动重启了。

还有一种方法是修改docker daemon使用TCP协议启动:

find / -name docker.service

使用find找到docker.service 文件 /lib/systemd/system/docker.service

vim /lib/systemd/system/docker.service

在 ExecStart=/usr/bin/dockerd 后面加入 -H tcp://127.0.0.1:4243,保存后

systemctl daemon-reload
systemctl restart docker.service

重启docker daemon,通过ss可以看到已经监听4243端口

[email protected]:/# ss -atol
State                  Recv-Q                  Send-Q                                    Local Address:Port                                     Peer Address:Port                  
LISTEN                 0                       128                                           127.0.0.1:4243                                          0.0.0.0:*                     
LISTEN                 0                       128                                       127.0.0.53%lo:domain                                        0.0.0.0:*                     
LISTEN                 0                       128                                             0.0.0.0:28022                                         0.0.0.0:*                     
LISTEN                 0                       5                                             127.0.0.1:ipp                                           0.0.0.0:*                     
LISTEN                 0                       128                                                [::]:28022                                            [::]:*                     
LISTEN                 0                       5                                                 [::1]:ipp                                              [::]:*    

同时需要设置环境变量$DOCKER_HOST。

$vim ~/.bashrc
export DOCKER_HOST=tcp://localhost:4243

这样就可以了

Cannot connect to the Docker daemon at tcp://xxx.xx.x.x:2376. Is the docker daemon running?

Cannot connect to the Docker daemon at tcp://xxx.xx.x.x:2376. Is the docker daemon running?

一.问题描述

   在用docker部署jenkins实现自动化部署服务时,报错:

二.问题分析:

   经前辈讲解得知,需要在Jenkins里面运行docker,而docker分为客户端和服务端,普通的docker命令由客户端操作,但客户端需要连接到服务端,而此时Jenkins是一个单独的容器,可以看做一个单独的系统,它不知道docker是谁,所以需要把docker映射进去了,但是我们映射的只是客户端,所以需要指定它连接到宿主机的服务端。在jenkins配置的docker也是客户端。

三.问题解决:

  在运行jenkins时,挂载所需的环境,在用docker-compose运行时,可以直接在docker-compose.yml添加相应的映射环境

 environment:
    DOCKER_HOST: tcp://xx.xx.xx.xx:2376

然后在储存驱动修改映射


{
  "hosts": [
        "tcp://xx.xx.xx.xx:2376",
        "unix:///var/run/docker.sock"
    ]
}

挂载相应文件目录

需要注意的是,上述映射的ip是jenkins所在的ip,因为jenkins是用户

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?

环境:centos7

问题:安装 docker 之后提示:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解决:

systemctl daemon-reload
systemctl restart docker.service

 

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? 解决

大概是docker容器设置restart-allways,然后重启Linux虚拟机后,发现很多进程。

但是这时候docker ps 就会报错

 

 

解决方法就是,需要reload 一下 daemon,然后restart docker,执行下面的两个命令

systemctl daemon-reload

systemctl restart docker.service

然后docker ps 发现可以了

 

 

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?错误

执行  

systemctl restart docker 

 问题解决

关于Ubuntu 18.04下Couldn't connect to Docker daemon at http+docker://localunixsocket解决办法的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Cannot connect to the Docker daemon at tcp://xxx.xx.x.x:2376. Is the docker daemon running?、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? 解决、Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?错误等相关内容,可以在本站寻找。

本文标签: