[SOLVED] Docker: Got permission denied while trying to connect to the Docker daemon socket at

If you are getting an error running the docker command as a non-root user,

devops@codetryout:~$ 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
devops@codetryout:~$ 


Solution: Provide group permission and docker.sock file permission.

Solution #1: Run the command using sudo

sudo docker <COMMAND>

Example for running the docker command using sudo:

devops@codetryout:~$ sudo docker run hello-world

Solution #2: Add user to the docker group

Provide group permission and docker.sock file permission by creating a user-group docker and adding the user to it

# Creating a group - docker
sudo groupadd docker

# Adding user to the group "docker"
sudo usermod -aG docker $USER

Provide read-write permission to docker.sock file

The below will fix the error, docker: Got permission denied while trying to connect to the Docker daemon socket.

sudo chmod 666 /var/run/docker.sock


Official documentation on post-install tasks, https://docs.docker.com/engine/install/l…stinstall/

Docker is a platform that allows developers to create, deploy and run applications in lightweight, portable containers. These containers provide a self-contained environment that includes all the dependencies and runtime required to run the application, ensuring consistent and reproducible execution across different environments. Docker simplifies the process of packaging, distributing, and managing software, making it easier to deploy applications seamlessly across various systems. This technology streamlines development workflows, enhances scalability, and promotes collaboration by providing a standardized environment for application deployment.