mac上用docker,不需要加sudo

来源:互联网 发布:淘宝考试不在延迟发货 编辑:程序博客网 时间:2024/05/25 21:33

mac上装完boot2docker之后,想测试一下docker,结果书上的例子出错:

$ sudo docker run hello-world           

Post http:///var/run/docker.sock/v1.19/containers/create: 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 run hello-world 


Hello from Docker.

This message shows that your installation appears to be working correctly.

...

原因如下:

When you use boot2docker, the docker daemon is running in a VM, essentially on a different machine. To communicate with adocker daemon on another machine, you must use the TLS connection (over HTTPS to the daemon's REST API). That's why you had to set upDOCKER_HOST and DOCKER_CERT_PATH. Since the daemon is running on a different machine, you don't need to be root to communicate with it because outgoing http connections don't require root, unlike trying to talk with theunix:///var/run/docker.sock socket.

But when you run sudo docker, suddenly you're a different user, you'reroot. The environment variables you set as your regular account are not set. So thedocker CLI uses its default communication method: the unix socket. The socket isn't there, because the daemon is running on a different machine (theboot2docker vm). Hence the error message.


原文地址:

http://stackoverflow.com/questions/27558496/installing-a-web-application-in-a-docker-container-dial-unix-var-run-docker-so

0 0
原创粉丝点击