Docker can start a container with a specific user by passing the id on the command line with -u
.
The parameter to the -u
switch is either a username or id of a user existing inside the container. More precisely,
the container must have valid /etc/passwd
file with the defined user:
$ mkdir etc
$ echo 'postgres:x:1000:1000::/home/postgres:/bin/sh' > etc/passwd
While not needed for this simple experiment, we might want to create group and shadow files for completeness: