I want to run the docker with my host account,

Normally I would do it with:

#!/bin/bash
user_home="${HOME:-"$(eval echo "~$(whoami)")"}"

docker run -it --rm \
  --env "USER=$(whoami)" \
  -u $(id -u ${USER}):$(id -g ${USER}) \
  --volume "${user_home}:${user_home}":ro \
  --volume /etc/passwd:/etc/passwd:ro \
  --volume /etc/group:/etc/group:ro \
  "ubuntu" /bin/bash

But now I need to do it on a PC that manages users with NIS (network information services) My user is not present in the /etc/passwd

What would be the best direction? Is it to somehow export users from NIS to some file and map it to /etc/passwd?

1

There are 1 best solutions below

1
On

Since you're running Docker from a script, you can add some automation to extract the necessary information to a temporary file. Something like this:

getent passwd $(id -un) > /tmp/passwd.docker
getent group  $(id -gn) > /tmp/group.docker

The getent command looks up information in whatever directory sources are configured on your system, so it will pull information from NIS.

You can then mount /tmp/passwd.docker and /tmp/group.docker into your container.

Alternately, you can just generate the information you need, since all you really care about is the uid and username:

cat > /tmp/docker.passwd <<EOF
$LOGNAME:x:$(id -u):$(id -g):fake entry:$HOME:/bin/bash
EOF

Etc.