无法连接到docker守护程序 [英] Cannot connect to docker daemon

查看:291
本文介绍了无法连接到docker守护程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过一切:添加用户,尝试使用sudo,但我没有修复它。



我尝试过:sudo docker ps和docker ps

Docker版本:1.11.2
操作系统/ Archlinux



给出错误:无法连接到Docker守护进程。 docker守护进程是否在此主机上运行?

  systemctl status docker:
●docker.service - Docker应用程序容器引擎
加载:加载(/usr/lib/systemd/system/docker.service;启用;供应商预设:禁用)
活动:活动(运行)自从Tue 08-16 12:34:14世界标准时间; 13分钟前
文件:https://docs.docker.com
主要PID:2323(docker)
任务:21(限制:4915)
内存:24.2M
CPU:649ms
CGroup:/system.slice/docker.service
├─2323/ usr / bin / docker守护程序-H fd://
└─2339docker-containerd - l / var / run / docker / libcontainerd /docker-containerd.sock --runtime docker-run
Aug 16 12:34:13 localhost docker [2323]:time =2016-08-16T12:34:13.730808484 Zlevel = info msg =[graphdriver] usin
Aug 16 12:34:13 localhost docker [2323]:time =2016-08-16T12:34:13.762838102Zlevel = info msg =Graph迁移到
Aug 16 12:34:13 localhost docker [2323]:time =2016-08-16T12:34:13.769883452Zlevel = info msg =Firewalld running:
Aug 16 12: 34:14 localhost docker [2323]:time =2016-08-16T12:34:14.023823826Zlevel = info msg =Default bridge(do
Aug 16 12:34:14 localhost docker [2323]: time =2016-08-16T12:34:14.179897054Zlevel = info msg =加载容器
Aug 16 12:34:14 localhost docker [2323]:time =20 16-08-16T12:34:14.179994020Zlevel = info msg =装载容器
8月16日12:34:14 localhost docker [2323]:time =2016-08-16T12:34:14.180008132Z level = info msg =daemon has complet
Aug 16 12:34:14 localhost docker [2323]:time =2016-08-16T12:34:14.180026066Zlevel = info msg =Docker daemoncom
Aug 16 12:34:14 localhost docker [2323]:time =2016-08-16T12:34:14.187118716Zlevel = info msg =API listen on 0.0。
Aug 16 12:34:14 localhost systemd [1]:启动Docker应用程序容器引擎。


ps aux | grep docker
root 2681 0.1 0.9 553580 35416? Ssl 12:59 0:00 / usr / bin / docker守护程序-H fd://
root 2694 0.0 0.3 287016 11724? Ssl 12:59 0:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc --start-timeout 2m
cuneyt 2835 0.0 0.0 11056 2228 pts / 1 S + 13:01 0:00 grep docker

编辑:当我运行手动docker守护进程正在工作,API侦听/var/run/docker.sock



当我启动它与systemctl启动docker API听0.0.0.0:3000我认为这是问题,但我不知道如何解决任何想法?

  systemctl cat docker.service 

[服务]
类型=通知
#默认是不使用systemd为cgroups,因为代理问题仍然
#存在,systemd目前不支持cgroup功能集所需
#由docker运行的容器
ExecStart = / usr / bin / docker守护程序-H fd://
MountFlags = slave
LimitNOFILE = 1048576
LimitNPROC = 1048576
LimitCORE = infinity
TimeoutStartSec = 0
#设置委托是的,以便systemd不重置docker容器的cgroup
Delegate = yes

[安装]
WantedBy = multiuser.target


解决方案

安装文档指出:


docker守护程序绑定到Unix套接字而不是TCP端口。由
默认,Unix套接字由用户root拥有,其他用户可以使用sudo访问它。因此,docker守护程序始终以
root用户身份运行。



因此,为了避免在使用docker命令时使用sudo,
创建一个名为docker的Unix组,并添加用户。当docker
守护程序启动时,它会使Docker组的Unix套接字的所有权读取/写入


要创建Docker组并添加您的用户:



以具有sudo权限的用户身份登录。 (你用来安装docker的人)
创建docker组。

  $ sudo groupadd docker 

将您的用户添加到docker组。

  $ sudo usermod -aG docker $ USER 

注销并重新登录。
这确保您的用户正在运行正确的权限。
通过运行没有sudo的docker来验证你的工作。

  $ docker run hello-world 

如果您仍然遇到相同的错误,请检查是否未为您的shell设置DOCKER_HOST环境变量。如果是,请取消设置。

  $ unset DOCKER_HOST 

希望这有助于


I have tried everything: add user, tried it with sudo but i didnt fix it.

I tried it as a : sudo docker ps and docker ps

Docker version : 1.11.2 OS/Archlinux

gives an error : Cannot connect to the Docker daemon. Is the docker daemon running on this host?

systemctl status docker :
 ● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service;  enabled;   vendor preset: disabled)
Active: active (running) since Tue 2016-08-16 12:34:14 UTC; 13min ago
 Docs: https://docs.docker.com
Main PID: 2323 (docker)
Tasks: 21 (limit: 4915)
Memory: 24.2M
  CPU: 649ms
CGroup: /system.slice/docker.service
       ├─2323 /usr/bin/docker daemon -H fd://
       └─2339 docker-containerd -l /var/run/docker/libcontainerd /docker-containerd.sock --runtime docker-run
Aug 16 12:34:13 localhost docker[2323]: time="2016-08-16T12:34:13.730808484Z" level=info msg="[graphdriver] usin
Aug 16 12:34:13 localhost docker[2323]: time="2016-08-16T12:34:13.762838102Z" level=info msg="Graph migration to
Aug 16 12:34:13 localhost docker[2323]: time="2016-08-16T12:34:13.769883452Z" level=info msg="Firewalld running:
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.023823826Z" level=info msg="Default bridge (do
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.179897054Z" level=info msg="Loading containers
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.179994020Z" level=info msg="Loading containers
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.180008132Z" level=info msg="Daemon has complet
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.180026066Z" level=info msg="Docker daemon" com
Aug 16 12:34:14 localhost docker[2323]: time="2016-08-16T12:34:14.187118716Z" level=info msg="API listen on 0.0.
Aug 16 12:34:14 localhost systemd[1]: Started Docker Application Container Engine.


ps aux | grep docker
root      2681  0.1  0.9 553580 35416 ?        Ssl  12:59   0:00 /usr/bin/docker daemon -H fd://
root      2694  0.0  0.3 287016 11724 ?        Ssl  12:59   0:00 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-runc --start-timeout 2m
cuneyt    2835  0.0  0.0  11056  2228 pts/1    S+   13:01   0:00 grep docker

EDIT : When i run manualy docker daemon is working and API listen on /var/run/docker.sock

When i start it with systemctl start docker API Listen on 0.0.0.0:3000 i think that is the problem but i dont know how to fix it any idea ?

systemctl cat docker.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/docker daemon -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

[Install]
WantedBy=multi-user.target

解决方案

The installation documentation states:

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.

So, To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

To create the docker group and add your user:

Login as a user with sudo privileges. (the one you used to install docker) Create the docker group.

$ sudo groupadd docker

Add your user to docker group.

$ sudo usermod -aG docker $USER

Log out and log back in. This ensures your user is running with the correct permissions. Verify your work by running docker without sudo.

$ docker run hello-world

If you're still getting the same error, check if the DOCKER_HOST environment variable is not set for your shell. If it is, unset it.

$ unset DOCKER_HOST

Hope this helps

这篇关于无法连接到docker守护程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆