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

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

    2018-08-19

    I have been stuck for days on this one and as I haven't found a complete answer with the why and how, I will post one for other people that stumble on the same problem and answers from above do not work.

    These are the 3 crucial steps when running Jenkins inside docker:

    1. You mount the socket /var/run/docker.sock to the jenkins container in order to be able to use the docker from the host.
    2. You have to install docker inside the container in order to use it. This is a great and simple article on how to do that. Note that newer versions might already have docker installed
    3. You run sudo usermod -a -G docker jenkins in order to add jenkins to the docker group. However, here you might run into a permission problem if the host docker and the container docker don't have the same group id so it is very important to adjust the container docker's gid to be the same as the host docker gid

    You can do this as a part of a launch script or simply by using exec and doing it manually: groupmod -g docker.

    Also, do not change permissions of the /var/run/docker.sock to 777 or stuff like that because that is a big security risk, you are basically giving everyone permission to use docker on your machine

    Hope this helps

提交回复
热议问题