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

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

    I am running Jenkins inside a docker container. The simplest solution for me was to make a custom image that dynamically sets the GID, like:

    FROM jenkins/jenkins:lts
    ...
    CMD DOCKER_GID=$(stat -c '%g' /var/run/docker.sock) && \
        groupadd -for -g ${DOCKER_GID} docker && \
        usermod -aG docker jenkins && \
        sudo -E -H -u jenkins bash -c /usr/local/bin/jenkins.sh
    

    See: https://github.com/jenkinsci/docker/issues/263

    Alternatively you could launch jenkins with the following options:

    -v /var/run/docker.sock:/var/run/docker.sock \
    -u jenkins:$(getent group docker | cut -d: -f3)
    

    This assumes your jenkins image has docker client installed. See: https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci

提交回复
热议问题