How to run docker with current host user, when users are managed with Linux NIS (Network Information Service)

蹲街弑〆低调 提交于 2021-01-28 11:42:57

问题


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:


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.



来源:https://stackoverflow.com/questions/65718839/how-to-run-docker-with-current-host-user-when-users-are-managed-with-linux-nis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!