You have your docker running in Ubuntu 22.04 (or older versions). When your normal user tries to run docker, it is failing because of a permission issue. The standard error is very confusing, such as:
dev@codetryout:~/scripts$ docker ps Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "https://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied
[Solution] Add the user to docker group ubuntu 22.04
It is quick and straightforward. By following the below steps you can grant access to a normal user. There is no docker restart required. However, to provide this permission, you would require sudo.
Create a UNIX group – docker
sudo groupadd docker
Add the user to the group
sudo usermod -aG docker $USER
Logout and login, then verify
The non-sudo user must log out to have the new privileges take effect.
dev@codetryout:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS ... d7c17f12345 rundeck/rundeck:4.5.0 "/tini -- docker-lib…" 5 hours ago Up 5 hours ...
What is the take away?
In this guide, we have gone through the steps for Ubuntu operating system feature that allows the user to run docker without entering sudo every time. This makes it easy for the user to use docker for development and testing purposes, you have learnt how to run ubuntu docker commands without sudo.
- Got permission denied while trying to connect to the Docker daemon socket at..
- Docker topics
- Ubuntu topics
- Virtual Machine Tips and tricks
If you have more questions, please feel free to ask.