Problem description
Running todayDocker PS
The 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.Root
Permission:
We found thatRoot
You can useDocker
Related commands, we want to useDocker
What should I do with related commands?
Let's goDocker mannual
Find 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 thatDocker
Process usageUNIX socket
InsteadTCP
Port. By default,UNIX socket
BelongRoot
User, needRoot
Permission.
How can we solve this problem?
Solution 1
UseSudo
Get administrator permissions and runDocker
Command (of course I do not recommend this method, because I have never succeeded, it seems that the above problem still occurs)
Solution 2
BecauseDocker
When the daemon is started, the default name isDocker
User Group read/writeUNIX socket
So you only need to createDocker
User Group, and add the current userDocker
In the user group, the current user has the permission to accessUNIX socket
And then you can executeDocker
Related 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