Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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". 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.

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?

like image 494
deSoul Avatar asked Dec 05 '25 15:12

deSoul


2 Answers

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

like image 180
Ryan.Bartsch Avatar answered Dec 08 '25 03:12

Ryan.Bartsch


Not exactly what you asked for.

You could set an environment variable before running your wrapper script. e.g.

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:

                args:
                    - GROUP_ID=${GROUP_ID}
like image 34
B.Z. Avatar answered Dec 08 '25 05:12

B.Z.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!