Docker Run Hello-World Still Fails, Permission Denied

How to fix docker: Got permission denied issue

If you want to run docker as non-root user then you need to add it to the docker group.

  1. Create the docker group if it does not exist
$ sudo groupadd docker

  1. Add your user to the docker group.
$ sudo usermod -aG docker $USER

  1. Log in to the new docker group (to avoid having to log out / log in again; but if not enough, try to reboot):
$ newgrp docker


  1. Check if docker can be run without root
$ docker run hello-world

Reboot if still got error

$ reboot

Warning

The docker group grants privileges equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface..

Taken from the docker official documentation:
manage-docker-as-a-non-root-user

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

If using jenkins

The user jenkins needs to be added to the group docker:

sudo usermod -a -G docker jenkins

Then restart Jenkins.

Otherwise

If you arrive to this question of stack overflow because you receive this message from docker, but you don't use jenkins, most probably the error is the same: your unprivileged user does not belong to the docker group.

You can do:

sudo usermod -a -G docker [user]

Insert your user name where [user] is.

You can check it was successful by doing grep docker /etc/group and see something like this:

docker:x:998:[user]

in one of the lines.

Then change your users group ID to docker (to avoid having to log out and log in again):

newgrp docker

getting permission denied in docker run

You need to change the permission of the bash file by chmod +x entrypoint.sh before calling ENTRYPOINT. So change your code to the following:

USER airflow
WORKDIR ${AIRFLOW_HOME}
RUN chmod +x entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

Rebuild the image and run the container, it should work.

docker.errors.DockerException: Error while fetching server API version or Permission denied error

Figured it out we need to add this to docker-compose file and give right permission to it below

 - //var/run/docker.sock:/var/run/docker.sock

sudo chmod 666 /var/run/docker.sock

This is how common-part of docker-compose file looks like now:

volumes:
- ./dags:/opt/airflow/dags
- ./logs:/opt/airflow/logs
- ./plugins:/opt/airflow/plugins
- //var/run/docker.sock:/var/run/docker.sock


Related Topics



Leave a reply



Submit