使用Linux NIS(网络信息服务)管理用户时,如何以当前主机用户运行docker [英] How to run docker with current host user, when users are managed with Linux NIS (Network Information Service)

查看:48
本文介绍了使用Linux NIS(网络信息服务)管理用户时,如何以当前主机用户运行docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我的主机帐户运行Docker,

I want to run the docker with my host account,

通常我会这样做:

#!/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

但是现在我需要在一台使用NIS(网络信息服务)管理用户的PC上进行此操作我的用户不在/etc/passwd

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

最好的方向是什么?是否以某种方式将用户从NIS导出到某个文件并将其映射到/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?

推荐答案

由于您是通过脚本运行Docker的,因此可以添加一些自动化功能以将必要的信息提取到临时文件中.像这样:

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

getent 命令在系统上配置的任何目录源中查找信息,因此它将从NIS中提取信息.

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

然后可以将/tmp/passwd.docker /tmp/group.docker 装入容器.

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

或者,您只需要生成所需的信息,因为您真正关心的只是uid和用户名:

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

等等.

这篇关于使用Linux NIS(网络信息服务)管理用户时,如何以当前主机用户运行docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆