为什么我在OS X上被迫用sudo运行docker?

时间:2016-10-30 01:48:03

标签: macos docker

我正在尝试在macOS 10.12.1上安装docker

我有一个较旧版本的docker,我从系统中删除了。

•我决定使用Docker for Mac Environment并利用hyperkit

•我没有任何可以使用

的现有容器

•我已完成Native mac app的全新安装,设置显示其正常运行

问题:作为标准用户运行docker ps失败

➜ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

成功:

➜ sudo docker ps
Password:
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

问题

如何防止必须以root权限运行?

其他信息

➜  bin ls -all | grep docker
lrwxr-xr-x    1 jmurphy  staff      67 Oct 29 21:43 docker -> /Users/jmurphy/Library/Group Containers/group.com.docker/bin/docker
lrwxr-xr-x    1 jmurphy  staff      75 Oct 29 21:43 docker-compose -> /Users/jmurphy/Library/Group Containers/group.com.docker/bin/docker-compose
lrwxr-xr-x    1 jmurphy  staff      75 Oct 29 21:43 docker-machine -> /Users/jmurphy/Library/Group Containers/group.com.docker/bin/docker-machine
lrwxr-xr-x    1 jmurphy  admin      75 Oct 29 20:50 docker-machine-driver-xhyve -> ../Cellar/docker-machine-driver-xhyve/0.2.3/bin/docker-machine-driver-xhyve
lrwxr-xr-x    1 jmurphy  staff      67 Oct 29 21:43 notary -> /Users/jmurphy/Library/Group Containers/group.com.docker/bin/notary


➜  bin ps aux | grep docker
jmurphy            815   0.5  1.2  4742256 103108   ??  S     9:43PM   0:22.64 /Applications/Docker.app/Contents/MacOS/com.docker.hyperkit -A -m 2G -c 2 -u -s 0:0,hostbridge -s 31,lpc -s 2:0,virtio-vpnkit,uuid=58fa3bf4-bc44-4df1-b637-b459084abef7,path=/Users/jmurphy/Library/Containers/com.docker.docker/Data/s50,macfile=/Users/jmurphy/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/mac.0 -s 3,virtio-blk,file:///Users/jmurphy/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2,format=qcow -s 4,virtio-9p,path=/Users/jmurphy/Library/Containers/com.docker.docker/Data/s40,tag=db -s 5,virtio-rnd -s 6,virtio-9p,path=/Users/jmurphy/Library/Containers/com.docker.docker/Data/s51,tag=port -s 7,virtio-sock,guest_cid=3,path=/Users/jmurphy/Library/Containers/com.docker.docker/Data,guest_forwards=2376;1525 -l com1,autopty=/Users/jmurphy/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty,log=/Users/jmurphy/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/console-ring -f kexec,/Applications/Docker.app/Contents/Resources/moby/vmlinuz64,/Applications/Docker.app/Contents/Resources/moby/initrd.img,earlyprintk=serial console=ttyS0 com.docker.driver="com.docker.driver.amd64-linux", com.docker.database="com.docker.driver.amd64-linux" ntp=gateway mobyplatform=mac -F /Users/jmurphy/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/hypervisor.pid
jmurphy            776   0.0  0.1 556636936   7780   ??  S     9:43PM   0:00.03 /Applications/Docker.app/Contents/MacOS/com.docker.driver.amd64-linux -db /Users/jmurphy/Library/Containers/com.docker.docker/Data/s40 -osxfs-volume /Users/jmurphy/Library/Containers/com.docker.docker/Data/s30 -slirp /Users/jmurphy/Library/Containers/com.docker.docker/Data/s50 -vmnet /var/tmp/com.docker.vmnetd.socket -port /Users/jmurphy/Library/Containers/com.docker.docker/Data/s51 -vsock /Users/jmurphy/Library/Containers/com.docker.docker/Data -docker /Users/jmurphy/Library/Containers/com.docker.docker/Data/s60 -addr fd:3 -debug
jmurphy            773   0.0  0.0 556622812   4068   ??  S     9:43PM   0:00.09 /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux
jmurphy            772   0.0  0.1 556677904  11868   ??  Ss    9:43PM   0:00.27 com.docker.driver.amd64-linux -db /Users/jmurphy/Library/Containers/com.docker.docker/Data/s40 -osxfs-volume /Users/jmurphy/Library/Containers/com.docker.docker/Data/s30 -slirp /Users/jmurphy/Library/Containers/com.docker.docker/Data/s50 -vmnet /var/tmp/com.docker.vmnetd.socket -port /Users/jmurphy/Library/Containers/com.docker.docker/Data/s51 -vsock /Users/jmurphy/Library/Containers/com.docker.docker/Data -docker /Users/jmurphy/Library/Containers/com.docker.docker/Data/s60 -addr fd:3 -debug
jmurphy            771   0.0  0.1 556627968   9128   ??  Ss    9:43PM   0:00.54 com.docker.osx.hyperkit.linux
jmurphy            770   0.0  0.1  2513388  11132   ??  Ss    9:43PM   0:00.21 com.docker.slirp --db /Users/jmurphy/Library/Containers/com.docker.docker/Data/s40 --ethernet fd:3 --port fd:4 --vsock-path /Users/jmurphy/Library/Containers/com.docker.docker/Data/@connect --max-connections 900
jmurphy            769   0.0  0.2  2476848  12716   ??  Ss    9:43PM   0:00.45 com.docker.osxfs --address fd:3 --connect /Users/jmurphy/Library/Containers/com.docker.docker/Data/@connect --control fd:4 --volume-control fd:5 --database /Users/jmurphy/Library/Containers/com.docker.docker/Data/s40
jmurphy            768   0.0  0.1  2475860  12252   ??  Ss    9:43PM   0:01.61 com.docker.db --url fd:3 --git /Users/jmurphy/Library/Containers/com.docker.docker/Data/database
jmurphy            767   0.0  0.0 556622812   3980   ??  S     9:43PM   0:00.10 /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux -watchdog fd:0
jmurphy            764   0.0  0.1 556679780   6492   ??  S     9:43PM   0:00.07 /Applications/Docker.app/Contents/MacOS/com.docker.osx.hyperkit.linux -watchdog fd:0
jmurphy           1887   0.0  0.0  2432804    840 s000  R+   10:18PM   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn docker
root               100   0.0  0.0  2444416   1800   ??  Ss    9:43PM   0:00.01 /Library/PrivilegedHelperTools/com.docker.vmnetd
jmurphy           1878   0.0  0.0 556614264   3888   ??  S    10:17PM   0:00.01 /Applications/Docker.app/Contents/MacOS/com.docker.frontend {"action":"vmstateevent","args":{"vmstate":"running"}}
jmurphy           1877   0.0  0.0 556631812   4108   ??  S    10:17PM   0:00.01 /Applications/Docker.app/Contents/MacOS/com.docker.frontend {"action":"vmstateevent","args":{"vmstate":"running"}}

来自文档: 在安装时,Docker for Mac提供基于Alpine Linux的HyperKit VM,运行Docker Engine。它在/var/tmp/docker.sock中的套接字上公开docker API。因为如果没有设置环境变量,这是docker看起来的默认位置,你可以开始使用docker和docker-compose而不设置任何环境变量。

https://docs.docker.com/docker-for-mac/docker-toolbox/

1 个答案:

答案 0 :(得分:12)

似乎这个问题是由于我的〜/ .zshrc文件中有遗产而引起的。

没有成功,我按照说明要求我运行的步骤进行了操作:

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair kp = kpg.generateKeyPair();

但是,如果〜/ .zshrc中的条目(可能是您的〜/ .bashrc)仍然存在 - 您可能需要手动删除它们并重新启动会话 - 之后您应该能够在不需要sudo的情况下运行命令。

 unset DOCKER_TLS_VERIFY
 unset DOCKER_CERT_PATH
 unset DOCKER_MACHINE_NAME
 unset DOCKER_HOST