HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

docker-compose.yml - make network name configurable via environment variable

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
configurabledockermakeenvironmentnamecomposeviaymlvariablenetwork

Problem

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?

Solution

It is possible via network name:

networks:
  mynetwork:
    name: ${STAGE_NAME}


where mynetwork - name "inside" stack

${STAGE_NAME} -name for other stacks/services/containers

See comment from docker capitan https://github.com/moby/moby/issues/40819#issuecomment-618726892

Code Snippets

networks:
  mynetwork:
    name: ${STAGE_NAME}

Context

StackExchange DevOps Q#6317, answer score: 13

Revisions (0)

No revisions yet.