0

even after adding sudo groupadd docker and sudo usermod -aG docker $USER , i cannot use docker commands without sudo

`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.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied.

So I had to use "sudo". How can I get ignored sudo in docker commands

ashique
  • 583
  • 4
  • 17
  • Did you log out and log in again, and/or run `newgrp docker`? See the more complete recipes in [How to fix docker: Got permission denied issue](https://stackoverflow.com/questions/48957195/how-to-fix-docker-got-permission-denied-issue). – David Maze Jan 05 '22 at 12:03

3 Answers3

1

Create a group called docker and add yourself to it using the commands

sudo groupadd docker
sudo usermod -aG docker $USER

Then you can run docker commands without using sudo.

Hans Kilian
  • 10,543
  • 1
  • 14
  • 21
0

Giving more access to this file solves the problem, but it is not recommended it gives every local process and user unrestricted root access over the host!

chmod 777 /var/run/docker.sock

then you don't need to use sudo but it's not recommended.

rezshar
  • 455
  • 1
  • 5
  • 14
  • 1
    `chmod 0777` is almost always wrong -- you pretty much never want a file that's both world-writeable and executable. For the Docker socket in particular you should make clear that "creates a security problem" is equivalent to "gives every local process and user unrestricted root access over the host"; that's a big enough problem that I wouldn't recommend it in an SO answer. – David Maze Jan 05 '22 at 12:02
  • yeah you are right. my post was edited. regards @DavidMaze – rezshar Jan 05 '22 at 12:12
0

Try restarting docker.

sudo groupadd docker
sudo usermod -aG docker $USER
sudo service docker restart
fam
  • 366
  • 1
  • 9