This article is an article to solve the error message. The error message is a specific error message appears upon executing a single command. The command is a command to execute a tool with the name of ‘docker’. Below is the output of the command execution :
user@localhost:~$ docker ps -a 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.39/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied user@localhost:~$
The above command, the ‘docker ps -a’ is part of the docker command for listing containers. There is an additional attribute or parameter of the command which is the ‘ps -a’ in the above command execution. It is an additional attribute or parameter for listing all the available containers. No matter if the containers are currently running or not.
So, in order to solve the above error message, just pay attention to the given information on it. The main focus of the given information is in the ‘permission denied’ part. Clearly that the ‘user’ does not have permission to connect to the socket specifically in ‘/var/run/docker.sock’. So, the logical solution to handle the above problem is for using another user whom has the permission or the privilege to connect to it.
Try using the ‘root’ or ‘super admin’ account to perform the command. The following are steps to be able to achive it :
1. Switch to ‘root’ or super user account in the operating system as follows :
sudo su -
The above command execution normally will have the following output :
user@localhost:~$ sudo su - [sudo] password for user: root@localhost:~#
2. After successfully switching to the ‘root’ or the super user account in the operating system, try to re-execute the above command as follows :
root@hostname:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0b4fc76de6c2 app "php index.php" 2 days ago Exited (0) 2 days ago test cd9384edb3d3 app "php index.php" 2 days ago Exited (0) 2 days ago app 78a60b523b4d 24d1a55b737d "/bin/sh -c 'apt-get…" 3 days ago Exited (100) 3 days ago xxxxxxx_xxxxxx ... root@hostname:~#