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.
In this context, we shall look into ways to resolve this Aws error.
How to fix AWS EC2 docker 'permission denied' 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:
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
5.Finally, re-login on the same server with ec2-user and check with any docker command:
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