2

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?

ChristianYami
  • 586
  • 1
  • 9
  • 17
brane
  • 585
  • 6
  • 20
  • If you need host files and host users, an isolation environment like Docker probably isn't a good technical match for you. Run the process directly on the host and you won't have to do anything special. – David Maze Jan 14 '21 at 13:14

1 Answers1

2

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.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • This worked, thanks --volume /tmp/passwd.docker:/etc/passwd:ro --volume /tmp/group.docker:/etc/group:ro – brane Jan 17 '21 at 11:47