Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

后端 未结 30 1568
孤独总比滥情好
孤独总比滥情好 2020-11-27 09:00

I am new to docker. I just tried to use docker in my local machine(Ubuntu 16.04) with Jenkins.

I configured a new job with below pipeline script.



        
相关标签:
30条回答
  • 2020-11-27 09:58
    chmod 777 /var/run/docker.sock
    

    This worked like a charm

    0 讨论(0)
  • 2020-11-27 09:59

    Success for me

    sudo usermod -a -G docker $USER
    reboot
    
    0 讨论(0)
  • 2020-11-27 09:59

    in my case it was just starting docker service :

    sudo service docker start
    
    0 讨论(0)
  • 2020-11-27 09:59

    If you want to keep it simple, use fixdockergid on your Dockerfile.

    0 讨论(0)
  • 2020-11-27 10:01

    The user jenkins needs to be added to the group docker:

    sudo usermod -a -G docker jenkins
    

    Then restart Jenkins.

    Edit

    If you arrive to this question of stack overflow because you receive this message from docker, but you don't use jenkins, most probably the error is the same: your unprivileged user does not belong to the docker group.

    You can do:

    sudo usermod -a -G docker alice
    

    or whatever your username is.

    You can check it at the end doing grep docker /etc/group and see something like this:

    docker:x:998:alice
    

    in one of the lines.

    Then change your users group ID to docker:

    newgrp docker
    
    0 讨论(0)
  • 2020-11-27 10:01

    2019-02-16

    Most of the steps were the same for me as the others has written. However, I was not able to add jenkins to the group docker using usermod with the mentioned solutions.

    I tried the following command from the docker host, and from the running docker container:

    sudo usermod -a -G docker jenkins
    

    (I entered to the running docker container with the following command from the docker host:

    docker exec -t -i my_container_id_or_name /bin/bash
    

    )

    Received from docker host:

    usermod: user 'jenkins' does not exist

    Received from docker container:

    We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
    

    [sudo] password for jenkins:

    I didnt know the password.

    Without the sudo part of the command, in the docker container I received:

    usermod: Permission denied. usermod: cannot lock /etc/passwd; try again later.

    Solution: I entered to the running docker container from the docker host with the following command:

    docker exec -t -i -u root my_container_id_or_name /bin/bash
    

    Now, I entered as root, and issued the following command:

    usermod -a -G docker jenkins
    

    Then, from the docker host, I restarted my running docker container with the following command:

    docker restart my_container_id_or_name
    

    After that, I started the jenkins job and it finished with success.

    I only used the root user to issue the usermod command for the user jenkins.

    0 讨论(0)
提交回复
热议问题