While trying to list containers in our machine –
docker container ls
We got the following error –
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
This happens when a user with insufficient privileges try to access the docker command. Though there are many ways to get the issue resolved, we cover two of those here.
Note: Following operations require superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.
Docker permission denied error in Ubuntu
I. Clearly, the user didn’t have the privileges to execute docker command. Therefore, one of the options is to go with superuser privileges (or, sudo). So, to list containers we can use –
sudo docker container ls
This should resolve the issue.
II. Alternately, we can make the user a part of docker group. This helps the user to acquire the required privileges. If you have installed Docker through standard Ubuntu repository. Then, you already have a group – docker. So, we can use adduser command-line utility to make the current user a part of the docker group.
This can be achieved through following command –
sudo adduser $USER docker
adduser – adds the $USER to the Group docker.
And, then reboot or logout to reflect the necessary changes. Thereafter, if you try to run the docker command it won’t throw permission denied error.
Besides, if you want to verify whether the $USER has been added to the group docker. We can do that through groups command-line utility –
Once you have added the $USER to the group docker, logged out and logged in. It would show the $USER a part of the group docker.
In conclusion, Docker permission error denied in Ubuntu comes up because the current user don’t have the privileges to execute docker commands. So, we covered here two methods which resolves the issue.