我试图学习Docker,但我一直收到(对我来说)神秘的错误消息。

可能最简单的例子是试图打印我安装的Docker版本:

$ sudo docker version
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): darwin/amd64
FATA[0000] Get http:///var/run/docker.sock/v1.16/version:
    dial unix /var/run/docker.sock: no such file or directory.
    Are you trying to connect to a TLS-enabled daemon without TLS?

我刚刚浏览了用户指南并严格遵循了每一步,所以我很惊讶我得到了这个消息……我现在该怎么办?

我刚刚注意到,如果我不使用sudo,我不会得到错误:

$ docker version
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): darwin/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3
Git commit (server): 5bc2ff8

当然,这不是一个解决方案,因为我可能需要在某个地方使用sudo。

我刚发现另一个页面说“如果你使用OS X,那么你不应该使用sudo。”我不知道他们是指这个例子,还是一般情况。


当前回答

我在MacOS上得到了同样的错误与sudo和没有它。

我已经解决了这个问题:

boot2docker start
$(boot2docker shellinit)

附注:多亏了艾伦。我发现这种方法在他们的官方文件中是推荐的。

P.S.2:有时在运行两个命令之前需要boot2docker init(谢谢Aaron)。

其他回答

在Linux Ubuntu/Mint上运行Docker所需要的一切:

sudo apt-get -y install lxc
sudo gpasswd -a ${USER} docker
newgrp docker
sudo service docker restart

可选地,如果上述方法不起作用,你可能需要安装两个额外的依赖项:

sudo apt-get -y install apparmor cgroup-lite
sudo service docker restart

Docker calls itself a self-sufficient runtime for Linux containers. In simple terms it acts both as server and client. The $ docker version command query is internal to the Docker executable and not to the daemon/service running. $ docker images or $ docker ps or $ docker pull centos are commands which send queries to the docker daemon/service running. Docker by default supports TLS connections to its daemon/service. Only if the user you are logged in as is part of user group docker or you have used sudo before the command, e.g. $ sudo docker images, does it not require TLS connectivity.

访问Docker文档保护Docker守护进程套接字。

滚动一点到顶部,找到警告部分的清晰度。

Docker守护进程绑定到Unix套接字,而不是TCP端口。默认情况下,Unix套接字由root用户拥有,其他用户只能使用sudo访问它。Docker守护进程始终以根用户运行。

sudo groupadd docker
sudo usermod -aG docker $USER

登出并重新登录,以便重新评估组成员资格。

docker run hello-world

来源:以非root用户管理Docker

另一个可能的原因是您的BIOS CPU可视化没有启用。先去启用它吧!

我遇到了同样的问题,并尝试了各种方法来解决这个问题,修改.bash_profile文件,登录和退出,但没有任何运气。最后,重启我的机器解决了这个问题。