Jenkins in docker with access to host docker

前端 未结 3 1963
星月不相逢
星月不相逢 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:40

    Please take a look at this docker file I just posted: https://github.com/bdruemen/jenkins-docker-uid-from-volume/blob/master/gid-from-volume/Dockerfile

    Here the GID extracted from a mounted volume (host directory), with

    stat -c '%g' 
    

    Then the GID of the group of the container user is changed to the same value with

    groupmod -g 
    

    This has to be done as root, but then root privileges are dropped with

    gosu  
    

    Everything is done in the ENTRYPOINT, so the real GID is unknown until you run

    docker run -d -v : ...
    

    Note that after changing the GID, there might be other files in the container no longer accessible for the process, so you might need a

    chgrp -R      
    

    before the gosu command.

    You can also change the UID, see my answer here Changing the user's uid in a pre-build docker container (jenkins) and maybe you want to change both to increase security.

提交回复
热议问题