From inside a container, I would like to get the id of a user on the host machine (what the command id -u username
would output, from the host).
Is there a way to accomplish this?
I thought I could mount /etc/passwd
in the container and grep
inside, but unfortunately the users are not listed in this file on our server (possibly related to the LDAP authentication mechanism?).
Thanks
2
I ended up solving this by mounting host folder /home
on my container, and getting the id of the owner of user's home dir /home/<user>
.
There's no way to get information about host users from inside a container. A design goal of Docker is that the host and containers are isolated from each other. A container has no concept of a host user; from the Docker daemon point of view, Docker doesn't even really know which user requested that a container be launched.
(This is doubly true if your host authentication system is something more complicated like an LDAP setup: a container simply may not have the tools or credentials required to query it, and the isolation means there's no way to somehow delegate to the host.)
If a principal goal of your application is to interact with host users, or the host filesystem, or you otherwise actively don't want Docker's isolation features, it's better to run your program outside of Docker.
answered Apr 9, 2020 at 17:46
David MazeDavid Maze
152k38 gold badges208 silver badges259 bronze badges
1