Resolved: Got permission denied while trying to connect to the Docker daemon socket in Docker
June 21, 2024 2024-06-02 10:58Resolved: Got permission denied while trying to connect to the Docker daemon socket in 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
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
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