AWS EC2 docker permission denied happens if the user do not have enough permission.
Are you trying to resolve AWS EC2 docker permission denied error? We can help you.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Docker permission configuration queries.
In this context, we shall look into ways to resolve this Aws error.
You may notice "permission denied" error while using docker commands from an EC2 instance.
The error might look as shown below:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
The above error message tells you that your current user can't access the docker engine, because of lacking permissions to access the Linux socket to communicate with the engine.
To resolve this error, simply follow the below steps:
1.Firstly cross check the error message by running the docker command again.
2.Next, 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.* ":
$ 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
You can see docker is installed with root user. The sock file has docker group permission.
3.Then, check if ec2-user is there in the docker group by running the below command.
cat /etc/group | grep docker
If you see the result as shown below it means the user is not in the docker group:
docker:x:497:
We need to have the user added to the docker group for the docker commands to run. thus to resolve the error, we need to configure ec2-user in the docker group by using usermod Linux command
$ sudo usermod -a -G docker ec2-user
4.Next, verify if ec2-user added in the docker group by running the below command:
$ cat /etc/group | grep docker
docker:x:497:ec2-user
5.Finally, re-login on the same server with ec2-user and check with any docker command:
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
This article covers methods to resolve AWS EC2 docker permission denied error.
To give docker user enough permission, do the following:
You can try adding prod-user to group Docker:
$ sudo usermod -a -G docker $USER
usermod is a command that modifies the system configuration for a specific user.
-a is a shortcut for --append: It means append the group to the list of groups the user belongs to.
-G is a shortcut for --groups: It tells usermod that the next argument is a group.
docker is the group we want to add $USER to.
$USER is the user that we want to modify.
If this alone doesn't resolve the issue then try below :
$ chmod 664 /var/run/docker.sock ## First try this.
$ chmod 777 /var/run/docker.sock ## Then this. Not recommended though due to full permission.