Add user to docker user group

Ordinary users often prompt insufficient permissions when using docker commands

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.26/containers/json: dial unix /var/run/docker.sock: connect: permission denied

insert image description here
This error can generally be solved by using the sudo command
insert image description here
, but every time you use the docker command, you need to add a sudo, which is still very troublesome; so a once-and-for-all method is needed: add the current user to the docker user group
1. Add the docker user group

sudo groupadd docker

insert image description here
2. Add the currently logged in user to the docker user group

sudo gpasswd -a $USER docker

insert image description here
3. Update the user group to make the modification take effect

newgrp docker

insert image description here
4. After testing, it is found that there is still a problem of no permission.
insert image description here
From the error log, it may be caused by insufficient permission of the /var/run/docker.sock file.
5. Check the permission of the /var/run/docker.sock file

ll /var/run/docker.sock

insert image description here
The owner of the file is root and the group it belongs to is also root. The owner and group of the file have read and write permissions to the file, and other users have no permissions to the file.
6. Try to add read and write permissions to other users

sudo chmod o+rw /var/run/docker.sock

insert image description here
7. Test again

insert image description here
There is no need to use sudo anymore

Guess you like

Origin blog.csdn.net/weixin_44835704/article/details/129123902