当我把Docker版本更新到0.8.0后,我在输入sudo Docker version时得到了一个错误消息:

Client version: 0.8.0
Go version (client): go1.2
Git commit (client): cc3a8c8
2014/02/19 12:54:16 Can't connect to docker daemon. Is 'docker -d' running on this host?

我按照说明,输入命令sudo docker -d,我得到了这个:

[/var/lib/docker|2462000b] +job initserver()
[/var/lib/docker|2462000b.initserver()] Creating server
open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory[/var/lib/docker|2462000b] -job initserver() = ERR (1)
2014/02/19 12:55:57 initserver: open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory

我怎么解决这个问题?


当前回答

I also had the same issue. The problem was in sockets allocated to docker-daemon and docker-client. First, permission was not set for the docker-client on docker.sock You can set it using "sudo usermod -aG docker $USER" Then check your bash file where the docker-client is running, For me it was on 0.0.0.0:2375, while docker-daemon was running on unix socket.(It was set in the configuration file of dockerd). Just comment the bash-line and it'll work fine. But if you want to make it work on TCP port instead of unix socket, change the configuration file of dockerd and set it on 0.0.0.0.2375 and keep the line in bash as it is if present or set it to 0.0.0.0:2375.

其他回答

如果你在OS X上运行Docker,运行下面的eval对我来说是有效的。

eval "$(docker-machine env default)"

如果你不想在每个终端会话上都运行这个eval语句,你可以在bash_profile中添加:

#Docker
eval "$(docker-machine env default)"

确保重新启动终端会话或在bash_profile上运行source以使更改生效。

我在Ubuntu 14.04上运行Docker 1.10时遇到了同样的问题,所有给出的答案都不能正常工作。对我来说,解决办法是在运行Docker守护进程时指定存储驱动程序。

sudo docker daemon --storage-driver=devicemapper

找出Docker不能工作的原因的最好方法是手动运行守护进程。

$ sudo service docker stop
$ ps aux | grep docker  # do this until you don't see /usr/bin/docker -d
$ /usr/bin/docker -d

Docker守护进程记录到STDOUT,因此它将开始输出它正在做的任何事情。

这就是我的问题所在:

[8bf47e42.initserver()] Creating pidfile
2015/01/11 15:20:33 pid file found, ensure docker is not running or delete /var/run/docker.pid

这是因为实例是从另一个虚拟机克隆的。我只需要删除pidfile,之后一切都正常了。

当然,我并不是盲目地假设这样可以工作,而是建议再次手动运行守护进程,并在启动服务备份之前检查日志输出是否有其他错误。

要修复此问题,您需要在终端中发出以下命令。我将解释每一步:

# Uninstall Docker from apt packages
$ sudo apt-get remove docker docker.io

# Remove it from the libraries just to be
# sure it's gone forever
$ sudo rm -rf /var/lib/docker/*

现在,如果你想简化事情并获得更多时间,你可以使用参数installDocker运行我的init脚本:

# Pull the init script from GitHub
$ wget https://github.com/dminca/dotfiles/blob/master/init

# Add rights to run the script
$ chmod 755 init

# Just run the script with the installDocker parameter
$ ./init installDocker

重新启动是可选的,但我建议您这样做,以确保一切正常运行。

如果上面所有的解决方案都不起作用,你可以尝试检查/var/run/docker.sock的所有权:

ls -l /var/run/docker.sock

如果你不是所有者,那么使用以下命令改变所有者:

sudo chown *your-username* /var/run/docker.sock

然后,您可以继续尝试轻松地执行Docker命令