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

后端 未结 30 1793
孤独总比滥情好
孤独总比滥情好 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 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.

提交回复
热议问题