In this docker tutorial, we explain how to solved permission denied while trying to connect to the docker daemon socket by ec2-user.
This kind of error you may get after docker installation. So In this docker tutorial, we are taking an example of Amazon Linux where we installed docker with root user.
Ec2-user don’t have enough permission to run any docker command, you will get below error when you try to docker command.
Step 1: Check Permission denied error
[ec2-user@Docker-sysadmin ~]$ docker images 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.38/images/json: dial unix /var/run/docker.sock: connect: permission denied [ec2-user@Docker-sysadmin ~]$
Step 2: Identify the issue while running the docker command by ec2-user?
As the error says there is permission denied, check out permission of docker files in “/var/run/docker.* ”
[ec2-user@Docker-sysadmin ~]$ ls -la /var/run/docker.* -rw-r--r-- 1 root root 4 Apr 15 05:05 /var/run/docker.pid srw-rw---- 1 root docker 0 Apr 15 05:05 /var/run/docker.sock [ec2-user@Docker-sysadmin ~]$
As you can see docker is installed with root user and for docker. The sock file has docker group permission.
Now, check out the user in the docker group and add all user who needs permission to run docker commands.
Step 3: Check ec2-user is there in the docker group
[ec2-user@Docker-sysadmin ~]$ cat /etc/group | grep docker docker:x:497: [ec2-user@Docker-sysadmin ~]$
Step 4: Configure ec2-user in the docker group by using usermod Linux command
[ec2-user@Docker-sysadmin ~]$ sudo usermod -a -G docker ec2-user [ec2-user@Docker-sysadmin ~]$
Step 5: Verify ec2-user added in the docker group
[ec2-user@Docker-sysadmin ~]$ cat /etc/group | grep docker docker:x:497:ec2-user [ec2-user@Docker-sysadmin ~]$
Step 6: Re-login on the same server with ec2-user and check with any docker command
[ec2-user@Docker-sysadmin ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest bb776ce48575 4 days ago 109MB tomcat latest f1332ae3f570 2 weeks ago 463MB centos latest 9f38484d220f 4 weeks ago 202MB amazonlinux latest 01da4f8f9748 6 weeks ago 162MB [ec2-user@Docker-sysadmin ~]$
Solved permission denied while trying to connect to the Docker daemon socket by ec2-user, you can follow the same steps for providing permission to any user in Linux.
Please drop your comments if you have any queries.
This is the end of the docker tutorial, solved permission denied while trying to connect to the Docker daemon socket.
amazing.. resolved issue and clear lot more doubt.. Thanks for guiding