Problem description
Running todayDocker PSThe following problem occurs during command execution:
Got permission denied while trying to connect to the docker daemon socket at Unix: // var/run/docker. sock: Get http: // % 2 fvar % 2 Frun % 2fdocker. sock/v1.38/containers/JSON: Dial UNIX/var/run/docker. sock: CONNECT: Permission denied
The prompt message seems to have insufficient permissions. Let's try.RootPermission:
We found thatRootYou can useDockerRelated commands, we want to useDockerWhat should I do with related commands?
Let's goDocker mannualFind the cause for the following reasons:
Manage docker as a non-root userthe docker daemon binds to a UNIX socket instead of a TCP port. by default that UNIX socket is owned by the user root and other users can only access it using sudo. the docker daemon always runs as the root user. if you don't want to use sudo when you use the docker command, create a Unix group called docker and add users to it. when the docker daemon starts, it makes the ownership of the UNIX socket read/writable by the docker group.
The above section indicates thatDockerProcess usageUNIX socketInsteadTCPPort. By default,UNIX socketBelongRootUser, needRootPermission.
How can we solve this problem?
Solution 1
UseSudoGet administrator permissions and runDockerCommand (of course I do not recommend this method, because I have never succeeded, it seems that the above problem still occurs)
Solution 2
BecauseDockerWhen the daemon is started, the default name isDockerUser Group read/writeUNIX socketSo you only need to createDockerUser Group, and add the current userDockerIn the user group, the current user has the permission to accessUNIX socketAnd then you can executeDockerRelated commands.
Run the following command to solve the problem:
Sudo groupadd docker # Add the docker user group sudo gpasswd-A $ user docker # Add the login user to the docker user group newgrp docker # update the user group docker PS # test whether the docker command can use sudo normally
Then we can solve this problem perfectly. The effect is as follows:
[Effective for test] solutions to got permission denied problems when running docker PS