[Effective for test] solutions to got permission denied problems when running docker PS

Source: Internet
Author: User
Tags docker ps

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.