How to Solve Error Message Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

Posted on

Introduction

The title of the article is describing an actual error message upon running a container using docker tool. So, the command is for running a container of an image. The following is the actual execution of the command :

[podman@10 ~]$ podman run -it centos /bin/bash
[root@a328282291a9 /]# [podman@10 ~]$ docker ps
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
[podman@10 ~]$ 

Actually, after running the command above for trying to run a container. There is a command after. It is the Ctrl+p and Ctrl+q. The command is to switch from the bash command line of the running container. So that the already running container can run in the background. The command line from the host machine will appear. But apparently, the execution of the command for listing the running container using ‘docker ps’ is failing. The container is running using the image from the previous command execution. The previous command is pulling an image of CentOS as follows :

[podman@10 registry]$ podman pull hello-world
Resolved "hello-world" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/hello-world:latest...
Getting image source signatures
Copying blob b8dfde127a29 [--------------------------------------] 0.0b / 0.0b
Copying config d1165f2212 done
Writing manifest to image destination
Storing signatures
d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
[podman@10 registry]$

Apparently, after running the container, it does not appear in the list using the ‘docker ps’ command. Although, there is another attempt to switch from a user to another user and then execute the ‘docker ps’ command as follows :

[podman@10 ~]$ exit
logout
[admin@10 ~]$ sudo su - podman
[sudo] password for admin:
Last login: Thu Apr  8 06:51:49 EDT 2021 on pts/1
[podman@10 ~]$ docker ps
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
[podman@10 ~]$ exit

Solution

As the searching process soon after giving some results, there are some conclusion about how to solve the error messages. The following are those conclusion :

  1. First of all, executing the ‘podman ps’ and ‘docker ps’ does not giving the same image list. It is because podman and docker are a different tool. So, it manages different images
  2. On the other hand, the execution of ‘podman’ with any given arguments or parameters is possible using any user account available in the operating system. But in case of ‘docker’, only super user, ‘root’ or any user that is a member of super user group can execute the docker command. The following are the execution of those command to prove the conclusion :
    [podman@10 ~]$ podman ps
    CONTAINER ID  IMAGE                         COMMAND               CREATED      STATUS          PORTS                   NAMES
    9b88d6c4aa70  quay.io/centos/centos:latest  /bin/bash             2 hours ago  Up 2 hours ago                          gracious_morse
    3e6c3a294bf2  docker.io/library/registry:2  /etc/docker/regis...  2 hours ago  Up 2 hours ago  0.0.0.0:5000->5000/tcp  registry
    [podman@10 ~]$
    
    [podman@10 ~]$ sudo docker ps
    [sudo] password for podman:
    CONTAINER ID   IMAGE                 COMMAND              CREATED        STATUS          PORTS                    NAMES
    6ca1c8cbf06d   httpd:latest          "httpd-foreground"   10 hours ago   Up 34 minutes   0.0.0.0:80->80/tcp       apache
    813e79d4eaea   portainer/portainer   "/portainer"         11 hours ago   Up 34 minutes   0.0.0.0:9000->9000/tcp   my_portainer
    [podman@10 ~]$
    

Leave a Reply