Specifying buildtime envars for docker-compose with multitiple files

The title is a little bit misleading, since you from the Docker Compose point of view you don’t want builtime environment variables (build args), only different variables for the submodules without the user knowing you there are additional variables.

--env-file as a parameter of docker compose is not the same as env_file in the yaml block of a service. --env-file is just an alternative of .env without specifying it for any service so Docker Compose could make those variables available as placeholders in the YAML file not in the containers, so it would not override anything directly inside the containers, but this is not necessary either…

What about using another docker cpmpose file in the modules.

docker-compose -f docker-compose.yml -f backend/docker-compose.yml up 

If you don’t want the user to remember this long command every time they run compose command, you can create a small script

up.sh

#!/usr/bin/env bash

args=(
  --file docker-compose.yml
  --file backend/docker-compose.yml
)
exec docker-compose "${args[@]}" up

But it would be probably easier to just define the additional env file as a required file in the modules like:

    env_file:
      - .runtime.env
      - backend/runtime.env