Docker replicate UID/GID in container from host

后端 未结 2 1336
暖寄归人
暖寄归人 2020-12-15 01:30

When creating Docker containers I keep running into the issue of the UID/GID not being reflected in the container (I realize this is by design). What I am looking for is a

2条回答
  •  被撕碎了的回忆
    2020-12-15 02:05

    You wouldn't want to run that as part of the image build process (in your Dockerfile), because the host on which someone is running a container is often not the host on which you are building the image.

    One way of solving this is passing in UID/GID information via environment variables:

    docker run -e APP_UID=100 -e APP_GID=100 ...
    

    And then have an ENTRYPOINT script that includes something like the following before running the CMD:

    useradd -c 'container user' -u $APP_UID -g $APP_GID appuser
    chown -R $APP_UID:$APP_GID /app/data
    

提交回复
热议问题