Permission analysis required to run docker

  • 2021-07-26 09:11:31
  • OfStack

root permissions are required to run docker.

Solve the problem that non-root users do not have permission to run docker commands by:

Method 1:

Use sudo to get administrator privileges and run docker command. This method has many limitations when executing docker command through script

Method 2:

When the docker daemon is started, the user group named docker will be given the permission to read and write Unix socket by default. Therefore, as long as the docker user group is created and the current user is added to the docker user group, the current user will have the permission to access Unix socket, and then the relevant commands of docker can be executed


sudo groupadd docker   # Add docker User group 
sudo gpasswd -a $USER docker   # Add the logged-in user to the docker User group 
newgrp docker   # Update user groups 

Additional:

How to Obtain root Permission in docker Container

First of all, your container must be running

You can view the container's CONTAINER ID through sudo docker container ls or sudo docker ps

Execute the command last (where 7509371edd48 is the CONTAINER ID found above)

sudo docker exec -ti -u root 7509371edd48 bash


Related articles: