我试图学习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。”我不知道他们是指这个例子,还是一般情况。


当前回答

在Ubuntu上安装lxc-docker后,你需要将你的用户添加到docker用户组:

sudo usermod -a -G docker myusername

这是因为套接字文件的权限:

srw-rw---- 1 root docker 0 Mar 20 07:43 /var/run/docker.sock

不要运行usermod没有“-a”,就像在其他评论中建议的那样,否则它会擦除你的额外组设置,只会离开“docker”组

事情是这样的:

➜  ~  id pawel
uid=1000(pawel) gid=1000(pawel) groups=1000(pawel),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare),998(docker)
➜  ~  usermod -G docker pawel
➜  ~  id pawel               
uid=1000(pawel) gid=1000(pawel) groups=1000(pawel),998(docker)

其他回答

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重启就解决了这个问题。

在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

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

当我用Jenkins创建Docker映像时,我也遇到了同样的问题。简单地将用户添加到docker组,然后重新启动docker服务,在我的情况下,我不得不重新启动Jenkins服务。

这是我得到的错误:

http:///var/run/docker.sock/v1.19/build?cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=59aec062a8dd8b579ee1b61b299e1d9d340a1340: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?
FATAL: Failed to build docker image from project Dockerfile
java.lang.RuntimeException: Failed to build docker image from project Dockerfile

Solution:

[root@Jenkins ssh]# groupadd docker
[root@Jenkins ssh]# gpasswd -a jenkins docker
Adding user jenkins to group docker
[root@Jenkins ssh]# /etc/init.d/docker restart
Stopping docker:                                           [  OK  ]
Starting docker:                                           [  OK  ]
[root@Jenkins ssh]# /etc/init.d/jenkins restart
Shutting down Jenkins                                      [  OK  ]
Starting Jenkins                                           [  OK  ]
[root@Jenkins ssh]#