有什么方法可以使用docker run --group-add为组指定组名和ID吗? [英] Is there any way to specify the group name AND id for a group with docker run --group-add?

查看:585
本文介绍了有什么方法可以使用docker run --group-add为组指定组名和ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我在脚本中有以下内容:

Currently I have something like the following in a script:

DOCKER_GROUP_ID=$(cut -d: -f3 < <(getent group docker))
...
docker run --group-add ${DOCKER_GROUP_ID} ...

问题是当我运行此脚本时,始终在结果容器中收到如下消息:

Problem is when I run this script, I get messages like the following in the resultant container all the time:

groups: cannot find name for group ID 999

解决方案

基于@TarunLalwani的回答,我的脚本中包含以下内容:

Based on the answer from @TarunLalwani I have the following in my script:

DOCKER_GROUP_ID=$(cut -d: -f3 < <(getent group docker))
CMD="docker run -d \                                                                                                                                                                                                                                                                                                                                                         
                --group-add ${DOCKER_GROUP_ID} \                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
                ${IDEA_IMAGE}"

echo $CMD
CONTAINER=$($CMD)

# Post-configuration                                                                                                                                                                                                                                                                                                                                                         
docker exec --user=root -it $CONTAINER groupadd -g $DOCKER_GROUP_ID docker                                                                                                                                                                                                                                                                                                   

docker attach $CONTAINER


推荐答案

这是预期的行为,因为组ID仅插入容器内而不插入其名称。因此,您可以运行id命令来查看仅不通过组ID传递组名

That is expected behavior because the group id is only inserted inside the container and not its name. So you can run the id command see that the group names are not passed only the group id

唯一的方法是运行命令 groupadd -g 999 docker 。这也将其添加到组文件中。但是您必须执行它,而docker不会帮您完成

The only way around would be to run the command groupadd -g 999 docker. This will add it to the group file also. But you have to execute it and docker won't do it for you

这篇关于有什么方法可以使用docker run --group-add为组指定组名和ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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