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
This error can generally be solved by using the sudo command
, 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
2. Add the currently logged in user to the docker user group
sudo gpasswd -a $USER docker
3. Update the user group to make the modification take effect
newgrp docker
4. After testing, it is found that there is still a problem of no permission.
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
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
7. Test again
There is no need to use sudo anymore