mac上用docker,不需要加sudo
阿新 • • 發佈:2019-01-09
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 a
docker
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 up
DOCKER_HOST
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 the
unix:///var/run/docker.sock
socket.
But when you run sudo docker
, suddenly you're a different user, you're
root
docker
CLI uses its default communication method: the unix
socket. The socket isn't there, because the daemon is running on a different machine (the
boot2docker
vm). Hence the error message.
原文地址: