Fix Docker permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
You might encounter this issue when you close and reopen your terminal session after adding your user to the docker group.
The error message “permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock typically occurs when the current user does not have the necessary permissions to access the Docker daemon.
To resolve this issue, you can add your user to the docker group, which grants the necessary permissions to interact with the Docker daemon without requiring sudo for every command.
sudo groupadd docker
sudo usermod -aG docker $USER
sudo reboot # It may be necessary to reboot your system for the changes to take effect.
docker ps # test connectionThere is an alternative solution if you need to work now, without rebooting your system. I do not recommend this approach as a permanent solution, but it can be used as a temporary workaround.
newgrp docker
sudo chmod 666 /var/run/docker.sock
docker ps # test connection