Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got permission denied while trying to connect to the Docker daemon socket while executing docker stop

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

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

What does this message mean?

like image 386
pcdro Avatar asked Oct 15 '17 19:10

pcdro


People also ask

How do I fix docker permission is denied?

Method 2: Run Docker Commands with sudo The "Permission Denied" error appears only with non-root users. Running the command with sudo to acquire root privileges usually resolves the issue.

How do I fix Permission denied while trying to connect to the docker daemon socket at Unix?

Fix 1: Run all the docker commands with sudo If you have sudo access on your system, you may run each docker command with sudo and you won't see this 'Got permission denied while trying to connect to the Docker daemon socket' anymore.


2 Answers

sudo usermod -a -G docker $USER

Reboot then run:

docker container run hello-world

it worked for me on ubuntu 18.2

like image 173
Jose Antonio Avatar answered Oct 12 '22 15:10

Jose Antonio


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)
like image 35
nickgryg Avatar answered Oct 12 '22 17:10

nickgryg