概述
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
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 the unix:///var/run/docker.sock
socket.
But when you run sudo docker
, suddenly you're a different user, you're root
. The environment variables you set as your regular account are not set. So the 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.
http://stackoverflow.com/questions/27558496/installing-a-web-application-in-a-docker-container-dial-unix-var-run-docker-so
最后
以上就是等待乌龟为你收集整理的mac上用docker,不需要加sudo的全部内容,希望文章能够帮你解决mac上用docker,不需要加sudo所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复