在执行docker stop时尝试连接到Docker守护进程套接字时获得的权限被拒绝

问题描述:

我在docker上运行了3个容器,我需要使用以下命令停止所有容器:

I have 3 containers running on my docker, and I need to stop all of them using the following:

sudo docker stop $(docker ps -q)

在运行命令时,我收到以下消息:

When a run the command I got this message:

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.32/containers/json: dial unix /var/run/docker.sock: connect: permission denied
See 'docker stop --help'.
Usage:  docker stop [OPTIONS] CONTAINER [CONTAINER...]
Stop one or more running containers

我进行了一些搜索,但消息显示的情况不适用于我的环境。我在Docker版本17.09.0-ce中使用Ubuntu 16.04 LTS,构建afdb6d4

I made some search, and the cases that message show does not apply to my environment. I'm using Ubuntu 16.04 LTS with Docker version 17.09.0-ce, build afdb6d4

此消息是什么意思?

似乎您的用户无法使用 docker 命令,因此您需要通过 sudo运行它也在括号中:

It seems your user cannot use docker command, so you need to run it via sudo in parentheses as well:

sudo docker stop $(sudo docker ps -q)