Blog

Resolved: Got permission denied while trying to connect to the Docker daemon socket in Docker

Docker

Resolved: Got permission denied while trying to connect to the Docker daemon socket in Docker

Once you have installed the Docker Engine in your machine and when you access the docker commands like create or list out the docker containers from your USER account, you may received an error, Got permission denied while trying to connect to the Docker daemon socket. I will display here the full error,

$ docker container ls

which means, you (current $USER) don’t have permission to access docker commands, so set the permission for non-root user then you need to add it to the docker group,Create a docker group if it does not exist already in your machine. The Group may created hopefully,

As a temporary solution, you can use sudo to run the failed command as root example,

$ sudo docker ps

However it is recommended to fix the issue by adding the current user to the docker group/ Create a docker group if it does not exist already in your machine. The Group may created hopefully,

$ sudo groupadd docker

Add your user to the docker group.

$ sudo usermod -aG docker $USER

Another option is,

You can change the permissions of docker socket to be able to connect to the docker daemon /var/run/docker.sock

$ sudo chmod 666 /var/run/docker.sock

Even, if doesn’t have permission to access the docker commands, reboot and check it again. It should be working fine. Next, run the docker container with NGINX latest version.

You can test the user permission issue using the command below,

$ docker run -itd --name nginx -p 8080:80 nginx:latest 

List out the running container,

$ docker container ls
Spread the love

Leave your thought here

Your email address will not be published. Required fields are marked *