Reputation: 1720
Issue: The groups attached to a Linux user are not visible inside the container.
Workflow:
user
and group
named sample:sample(8000:8000)
is created./etc/passwd
file with readOnly
access.Command: docker run -itd --user "8000:8000" -v /etc/passwd:/etc/passwd:ro docker_image_name:latest bash
Note: The user & group sample:sample(8000:8000) also exists on the host.
Command 1: whoami
Output: sample
Command 2: id -u
Output: 8000
Command 3: id -g
Output: 8000
Command 4: groups
Output: sample
Observations:
Expected Behaviour: As the sample user is present on host as well as the container, I want the groups associated with the host user inside the container as well, i.e., I want the host user details to override the ones present in the container.
Upvotes: 1
Views: 2159
Reputation: 1720
The issue lies in the way Docker loads the user and group information.
Issues are already reported to Docker as it fails to load the additional groups information which is stored in /etc/groups
file, so, even if we mount the /etc/groups
file Docker doesn't honor it.
Hence, the solution is to associate the required groups using the --group-add
option provided by docker.
Note: This group provided must be a valid group and it will then be associated to your user with the already existing groups.
Upvotes: 3