当前位置: 首页>>技术问答>>正文


无法连接到Docker守护程序。 docker守护程序是否在此主机上运行?

,

问题描述

我在ubuntu 14.04上安装了docker,它告诉我安装成功。然后我输入了sudo docker version,它返回了

Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.2
 Git commit:   a34a1d5
 Built:        Fri Nov 20 13:12:04 UTC 2015
 OS/Arch:      linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

我进入了sudo service docker status

docker start/running, process 8063

我试过sudo docker imagessudo docker info,得到了同样的答复:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

我不知道为什么它返回了这个,我试图使用sudo docker pull ubuntu拉ubuntu,并得到了

Using default tag: latest
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

请告诉我如何解决这个问题,如何拉动和运行docker图像。 docker -ddocker deamon相同吗?

最佳解决思路

您需要将当前用户添加到docker组,如下所示:

sudo usermod -aG docker <your username>

此外,您可以使用USER环境变量,如:

sudo usermod -aG docker $USER

然后重启系统。正如码头工程师documentation所说:

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.

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.

次佳解决思路

如果将用户添加到docker组不起作用,请尝试重新启动该服务:

sudo service docker restart 

第三种解决思路

对我有用的唯一方法(在ubuntu xenial上):

sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
newgrp docker

找到here

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/7224.html,未经允许,请勿转载。