问题描述
我在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 images
和sudo 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 -d
与docker 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 thedocker
command, create a Unix group calleddocker
and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by thedocker
group.
次佳解决思路
如果将用户添加到docker
组不起作用,请尝试重新启动该服务:
sudo service docker restart
第三种解决思路
对我有用的唯一方法(在ubuntu xenial上):
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
newgrp docker
找到here