How to specify both uid and username on `docker run` command?

1.3k views Asked by At

To start a docker container with the current user I can call docker run with the --user parameter like

docker run --user $(id -u):$(id -g) myimage

However that leaves the user inside the container without a name which inhibits the execution of some programs. For example it is not possible to mount a directory via fuse as a user without a name.

So what is the preferred approach to specify the UID and the username for a docker run command?

The only workaround I have found so far is to bind-mount /etc/password into the container:

docker run -v /etc/passwd:/etc/passwd:ro --user $(id -u):$(id -g) myimage

but that looks rather ugly to me. Isn't there a better way to do this?

0

There are 0 answers