The main process's user is set by the --user option when the container is created; docker exec runs as the same user by default.
docker looks up the name after --user in the image's /etc/passwd, and alpine has no student user. Numbers always work: --user 1000:1000 is student's UID and GID, though id inside prints them without names.
The number after the colon is the group. Without it, the process gets group 0, which is the root group.
A container started with --user 1000 created a file in a directory on the machine. Who will ls -l show as the owner and group of that file?
-
The file's owner comes from the process UID, which is 1000 — that is student. root remains only in the group.
-
The group is set by the number after the colon in
--user. Without it, the process runs with GID 0, and the file gets the root group.
Without a GID after the colon, the process runs with group 0. The file gets the owner student and the group root, which is why --user is written as a pair: 1000:1000.
Key points
- A process's UID in a container is the same UID on the machine: root inside is root for the host files mounted in.
-
--user UID:GIDsets the main process's user;docker execruns as the same user. -
A name in
--useris looked up in the image, numbers always work; without a GID the process group is root.