Jenkins in docker with access to host docker

前端 未结 3 1958
星月不相逢
星月不相逢 2021-01-02 01:14

I have a workflow as follows for publishing webapps to my dev server. The server has a single docker host and I\'m using docker-compose for managing containers.

    <
3条回答
  •  臣服心动
    2021-01-02 01:48

    My previous answer was more generic, telling how you can modify the GID inside the container at runtime. Now, by coincidence, someone from my close colleagues asked for a jenkins instance that can do docker development so I created this:

    FROM bdruemen/jenkins-uid-from-volume
    RUN apt-get -yqq update && apt-get -yqq install docker.io && usermod -g docker jenkins
    VOLUME /var/run/docker.sock
    ENTRYPOINT groupmod -g $(stat -c "%g" /var/run/docker.sock) docker && usermod -u $(stat -c "%u" /var/jenkins_home) jenkins && gosu jenkins /bin/tini -- /usr/local/bin/jenkins.sh
    

    (The parent Dockerfile is the same one I have described in my answer to: Changing the user's uid in a pre-build docker container (jenkins))

    To use it, mount both, jenkins_home and docker.sock.

    docker run -d /home/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock 
    

    The jenkins process in the container will have the same UID as the mounted host directory. Assuming the docker socket is accessible to the docker group on the host, there is a group created in the container, also named docker, with the same GID.

提交回复
热议问题