docker-compose.yml - make network name configurable via environment variable I have a docker compose file with env variables for stage specific configurations. As long as env variables are used in values in docker-compose.yml everything is fine, but the problem is with the network name, since it's specified in the tag.

networks:
  mynetwork.${STAGE_NAME}:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: ${STAGE_NETWORK_PREFIX}.0/24


Any chance to get the network name mynetwork.${STAGE_NAME} configurable from outside?
If you have envsubst installed (part or gnu gettext) you can use something like that:

export STAGE_NAME="xyz"
export STAGE_NETWORK_PREFIX="1.2.3.4"
docker-compose -f &lt;(envsubst docker-compose.yml) ...


If your shell does not support process substitution, something like that would do the trick:

envsubst docker-compose.yml | docker-compose -f - ...