0

I want to execute a perl script inside a docker container as root (SUDO on the host), and get the real user id inside the perl script.

For eg., below execution should enable myscript.pl to get the real userId (mat in this case), without having to pass it explicitly as an additional parameter to myscript.pl.. (The script inside the container when invoked from the host should find the real user invoking the script)

[mat@dev01-nrg02 ~]$ sudo docker exec -it MY_API_LAYER myscript.pl 

Setting as docker environment variables during start-up of the container is ruled out, since

  1. The script would be executed by any user, and i need to get that user's real Id.
  2. The docker container is started up using an Init service...so this would mean technically also there is no possibility to set any user detail...

Also..

I do not want to trouble the users of the script by having them to pass their userId (which could appear as redundant, also they could pass any Id, if such an option is provided..)

Please let me know if anyone has had such a problem and resolved it?

Joby Job
  • 1
  • 2

1 Answers1

0

You can't find this out.

A Docker container is pretty isolated from the calling user. This is doubly true in the case of a docker exec call: at some point in time some host user invoked the root Docker daemon to start a container, and then at some later point in time some other host user is making a call to the root Docker daemon to run a process as some other user inside the container.

If you need a user to run a script, as their own ID, on their own files, it will be significantly easier to install the dependencies required so they can run the script as themselves, without a sudo or docker layer

$ myscript.pl
David Maze
  • 130,717
  • 29
  • 175
  • 215