我想转移到Docker,所以我刚刚开始摆弄它。我已经在VirtualBox Ubuntu 15.10 (Wily Werewolf)安装上安装了Docker,然后按照这里的建议,我尝试运行一个基本的nginx Docker镜像:

$ docker run --name mynginx1 -P -d nginx
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

所以我检查了Docker是否在运行:

$ sudo service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since vr 2015-11-06 08:41:48 CET; 15min ago
     Docs: https://docs.docker.com
 Main PID: 7542 (docker)
   CGroup: /system.slice/docker.service
           └─7542 /usr/bin/docker daemon -H fd://

nov 06 08:41:47 kramer65-VirtualBox systemd[1]: Starting Docker Application Container Engine...
nov 06 08:41:47 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:47.900410966+01:00" level=info msg="API ...ock"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.033514149+01:00" level=info msg="Fire...lse"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.141594321+01:00" level=info msg="Defa...ess"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.416294436+01:00" level=warning msg="Y...it."
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.565507576+01:00" level=info msg="Load...rt."
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567907022+01:00" level=info msg="Load...ne."
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567945214+01:00" level=info msg="Daem...ion"
nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567969891+01:00" level=info msg="Dock....9.0
nov 06 08:41:48 kramer65-VirtualBox systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

这表明Docker守护进程实际上已经在运行,但为了确保我只是手动启动了Docker守护进程:

$ sudo docker daemon
INFO[0000] API listen on /var/run/docker.sock           
INFO[0000] [graphdriver] using prior storage driver "aufs" 
INFO[0000] Firewalld running: false                     
INFO[0000] Default bridge (docker0) is assigned with an IP address XXX.XX.X.X/XX. Daemon option --bip can be used to set a preferred IP address 
WARN[0000] Your kernel does not support swap memory limit. 
INFO[0000] Loading containers: start.                   

INFO[0000] Loading containers: done.                    
INFO[0000] Daemon has completed initialization          
INFO[0000] Docker daemon                                 commit=76d6bc9 execdriver=native-0.2 graphdriver=aufs version=1.9.0

然后我尝试再次运行图像,但结果相同:

$ docker run --name mynginx1 -P -d nginx
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

我试着执行命令,但没有效果。我哪里做错了?


当前回答

在安装一切并启动服务后,尝试关闭终端并再次打开它,然后尝试拉出映像

Edit

我也有这个问题,如果上面的解决方案不会工作,尝试这个解决方案,这是命令下面

sudo mv /var/lib/docker/network/files/ /tmp/dn-bak

注意事项

如果上面的命令工作,你可能有网络docker问题,无论如何这解决了它,要确认,请参阅下面命令的日志

tail -5f /var/log/upstart/docker.log

如果输出是这样的

FATA[0000] Error starting daemon: Error initializing network controller: could not delete the default bridge network: network bridge has active endpoints 
/var/run/docker.sock is up

你确实有网络问题,但我不知道下次重启(更新,2个月没有问题)你的操作系统是否会再次遇到这个问题,这是一个错误还是安装问题

我的docker版本

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

Server:
 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

其他回答

将用户添加到docker组

如果docker组不存在,添加它: Sudo groupadd docker 将连接用户${user}加入docker组: sudo gpasswd -a ${USER} docker 重启Docker守护进程: Sudo服务docker重启 要么执行newgrp docker,要么注销/登录以激活对 组。

需要将当前用户加入docker组,操作步骤如下:

sudo usermod -aG docker $(whoami)

然后登出并重新登录系统或重新启动系统。 根据docker版本进行测试

有关如何安装docker-engine的进一步信息,请参阅docker文档

也许这将帮助某些人,因为错误消息非常没有帮助,而且我已经多次执行所有标准许可步骤,但都无济于事。

Docker偶尔会在阻碍访问的地方留下幽灵环境变量,尽管您的系统在其他方面是正确设置的。下面的shell命令可以使它再次可访问,如果你已经让它运行了一点,它只是在重新启动后停止合作:

unset DOCKER_HOST
unset DOCKER_TLS_VERIFY
unset DOCKER_TLS_PATH
docker ps

I had a previously working docker install, and after rebooting my laptop it simply refused to work. Was correctly added to the docker user group, had the correct permissions on the socket, etc, but could still not run docker login, docker run ..., etc. This fixed it for me. Unfortunately I have to run this on each reboot. This is mentioned on a couple of github issues also as a workaround, although it seems like a bug that this is a persistent barrier to correct operation of Docker (note: I am on Arch Linux, not OSX, but this was the same issue for me).

这个问题目前在谷歌搜索中排名第三。在我的Linux系统上做了一些研究来解决这个问题之后,我想我应该写下这个答案。最初的帖子说这个问题是在Ubuntu上,但我使用Fedora时也遇到了这个问题。考虑到这一点,下面是我解决这个问题的方法。

在Fedora 22上

安装码头工人:

$> curl -fsSL https://get.docker.com/ | sh

安装Docker后:

需要将用户添加到docker组。

$> sudo usermod -aG docker

docker守护进程需要启动

$> sudo service docker start

您可以将守护进程设置为在引导时启动

$> sudo chkconfig docker on

您可以验证docker服务是否正在运行

$> service docker status

最后一个检查

$> docker run hello-world

由于docker在启动时绑定到一个由root拥有的unix套接字,因此使用'sudo'和docker命令一起工作。