[docker] Solve the problem of insufficient permissions for non-root users to execute docker commands: /var/run/docker.sock: connect: permission denied

After installing docker, execute the docker command, prompting no permission.

sGot permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get …/containers/json?all=1": dial unix /var/run/docker.sock: connect: permission denied

Solution

1. Use the root user to operate docker, and the company generally does not give root permission. . .

2. Add the current operating user to the docker group, and the docker group will be created by default during installation

$ sudo gpasswd -a $USER docker 
Adding user qard to group docker

$ newgrp docker

Execute the docker command again, and it can be used normally.

$ docker ps 
..
$ docker images
..

If it still doesn't work, restart docker

$ sudo systemctl restart docker

Guess you like

Origin blog.csdn.net/lan_yangbi/article/details/122309899