简体   繁体   English

将 shell 命令结果从 docker-compose 传递给 Dockerfile

[英]Pass shell command results to Dockerfile from docker-compose

i trying to pass user group ID from my Linux environment to Dockerfile throught docker-compose.我试图通过 docker-compose 将用户组 ID 从我的 Linux 环境传递到 Dockerfile。 I know about about "args" in docker-compose.yml, but i need to find method for getting group id by executing shell commang "getent group mygroup | cut -d: -f3".我知道 docker-compose.yml 中的“args”,但我需要通过执行 shell commang “getent group mygroup | cut -d: -f3”来找到获取组 ID 的方法。 This is a mandatory requirement, because then the container will be distributed in different environments where the name of the group is known, and the id will be different.这是一个强制性要求,因为这样容器将分布在不同的环境中,其中组的名称是已知的,并且 id 会有所不同。

Here is what i talking about:这就是我所说的:

    version: '3.3'
    services:
    ...
        php:
            build:
                context: './php-fpm'
                args:
                    - GROUP_ID=<HERE I NEED TO GET SHELL COMMAND RESULTS>
            container_name: php-fpm
    ...

Is any methods to do that?有什么方法可以做到这一点吗?

Is something like this what you're after像这样的东西是你所追求的

$groupid = getent group mygroup | cut -d: -f3
docker-compose up --build --build-arg GROUP_ID=$groupid

or are you hoping to have the groupid command in the docker-compose script还是您希望在 docker-compose 脚本中有 groupid 命令

Not exactly what you asked for.不完全是你要求的。

You could set an environment variable before running your wrapper script.您可以在运行包装脚本之前设置环境变量。 eg例如

export GROUP_ID=`getent group mygroup | cut -d: -f3`
run wrapper script to call your docker-compose file

Then you can retrieve the GROUP_ID inside your docker-compose file:然后您可以在 docker-compose 文件中检索 GROUP_ID:

                args:
                    - GROUP_ID=${GROUP_ID}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM