Changing the user's uid in a pre-build docker container (jenkins)

前端 未结 3 960
半阙折子戏
半阙折子戏 2021-02-14 15:50

I am new to docker, so if this is a fairly obvious process that I am missing, I do apologize for the dumb question up front.

I am setting up a continuous integration ser

3条回答
  •  执念已碎
    2021-02-14 16:18

    Please take a look at the docker file I just uploaded: https://github.com/bdruemen/jenkins-docker-uid-from-volume/blob/master/Dockerfile . Here the UID is extracted from a mounted volume (host directory), with

    stat -c '%u' 
    

    Then the UID of the container user is changed to the same value with

    usermod -u 
    

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

    gosu  
    

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

    docker run -d -v : ...
    

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

    chown -R  
    

    before the gosu command.

    You can also change the GID, see my answer here Jenkins in docker with access to host docker and maybe you want to change both to increase security.

提交回复
热议问题