Set docker image username at container creation time?

后端 未结 3 1017
情话喂你
情话喂你 2021-02-07 09:10

I have an OpenSuse 42.3 docker image that I\'ve configured to run a code. The image has a single user(other than root) called \"myuser\" that I create during the initial Image g

3条回答
  •  隐瞒了意图╮
    2021-02-07 10:02

    Usernames are not important. What is important are the uid and gid values.

    User myuser inside your container will have a uid of 1000 (first non-root user id). Thus when you start your container and look at the container process from the host machine, you will see that the container is owned by whatever user having a uid of 1000 on the host machine.

    You can override this by specifying the user once you run your container using:

    docker run --user 1001 ...
    

    Therefore if you want the user inside the container, to be able to access files on the host machine owned by a user having a uid of 1005 say, just run the container using --user 1005.

    To better understand how users map between the container and host take a look at this wonderful article. https://medium.com/@mccode/understanding-how-uid-and-gid-work-in-docker-containers-c37a01d01cf

提交回复
热议问题