12

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?

pcdro
  • 307
  • 1
  • 4
  • 16
  • 1
    docker post-installation steps: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user – radistao Jul 26 '19 at 15:00

3 Answers3

11
sudo usermod -a -G docker $USER

Reboot then run:

docker container run hello-world

it worked for me on ubuntu 18.2

ltd9938
  • 1,444
  • 1
  • 15
  • 29
Jose Antonio
  • 840
  • 14
  • 25
8

If you are getting "permission denied" that probably means you haven't added yourself in users group which can operate upon docker. To fix that, go to your terminal and type:

sudo usermod -aG docker <name-of-user-to-grant-permission>

The 'docker' parameter is group created upon installing docker, and you can check that by typing:

getent group | grep docker

And the second parameter is the user you are adding to the group. The list of users you can check by typing:

getent passwd

For more information about command usermod you can find here.

UPDATED: I installed docker again and just remembered that when you apply this command you need to restart your machine.

Marko
  • 443
  • 6
  • 12
5

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)
nickgryg
  • 25,567
  • 5
  • 77
  • 79
  • I thought that if I use the first 'sudo' it would apply for the second command of Docker, new I understood why I was getting this error. – pcdro Oct 16 '17 at 20:38