I'm trying to run a Docker container with a custom made image, with a given user. I have an entrypoint.sh
, that can change the running user according to an environment variable provided at the Docker command line, with -e USER=myuser
.
I have the very same user in the host machine. This can be done in different host machines, and I can ensure this user exists in any host we use. But I'm having troubles because I cannot ensure that the numerical id for this user is always the same (say 1001). At the Docker container execution command line I mount some local folders with -v <src>:<tgt>
, and the application in the container creates additional folders and files in <tgt>
.
The problem is that although the user in the host and the container have the same name (say myuser
), the numerical id for it can change (say e.g. 5000
in the host and 1001
in the container), so I get problems when reading files and folders under the mounted path.
What is the best solution to ensure that, at execution time, not only the user name but also the user id is the same in the host and in the running container?
EDIT
I see I did not explain myself AT ALL, and mixed things. I will try to explain my problem again:
I did create a Linux-based image, and in this image I: a) installed a set of packages as
root
; b) created a certain usermyuser
, and switched to that user withUSER <usr>
in the Dockerfile; and c) copied my own software and installed in the image, as the usermyuser
, and this software must be executed by that user.I created the very same user
myuser
in another machinelaunched a container from this image, in another machine, and shared some folders (owned by the user
myuser
) from the host file system with that container.
The problem appeared because the numerical id for the user myuser
was 1001 in the Docker image, and 5000 in the other host, when the container was executed.
One solution would be to force the numerical id being the same any time the user gets created in any host machine. The problem is that I cannot be sure this will be always possible in the host that runs the images.