Even after going through lot of materials and SO answers still I'm not clear on docker uid/user usage or implementation.
I understand the below points:
With the above all said, when I have the below command in my Dockerfile, I presume that a new user (my-user
) will be created with incremented uid.
RUN addgroup my-group && adduser -D my-user -G my-group
What happens if I run the same image multiple times i.e multiple containers? Will the same uid
be assigned to all processes?
What happens if I add same above command in another image and run that image as container? - will I get new uid
or same uid
as the previous one?
How the uid
increment happens in Container in relation with the host machine.
Any pointers would be helpful.
User ID (UID) and Containers. The UID, GID pair and SELinux executing the containers are the ones used as the effective UID to execute the Entrypoint command defined by the Container.
Docker assigns a unique ID to each container. The full container ID is a hexadecimal string of 64 characters.
4. Using sudo Command Inside the Container. Docker containers typically run with root as the default user. To share resources with different privileges, we may need to create additional users inside a Docker container.
Absent user namespace remapping, there are only two things that matter:
/etc/passwd
file.Remember that each container and the host have separate filesystems, so each of these things could have separate /etc/passwd
files.
What happens if I run the same image multiple times i.e multiple containers? Will the same uid be assigned to all processes?
Yes, because each container gets a copy of the same /etc/passwd
file from the image.
What happens if I add same above command in another image and run that image as container? - will I get new uid or same uid as the previous one?
It depends on what adduser
actually does; it could be the same or different.
How the uid increment happens in Container in relation with the host machine.
They're completely and totally independent.
Also remember that you can docker push
/docker pull
a built image to run it on a different host. That will bring the image's /etc/passwd
file along with it, but the host environment could be totally different. Correspondingly, it's not a best practice to try to match some specific host's uid mapping in a Dockerfile, because it will be wrong if you try to run the same image anywhere else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With