Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/dock...

非root用户在执行 docker ps报如下错误

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied

原因:访问unix socket需要root权限
docker启动守护进程时会默认创建docker用户组,docker用户组拥有unix socket的读写权限,这里将当前非root用户加入用户组即可以正确运行命令。

sudo gpasswd -a $USER docker
# $USER 为加入用户组用户名

你可能感兴趣的:(Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/dock...)