Docker-compose set subnet as variable results to "should use the CIDR format"

2.1k Views Asked by At

I am setting the subnet and gateway in my docker-compose file as variables. It looks like this:

networks:
    btgnetwork:
        driver: bridge
        ipam:
            driver: default
            config:
                - subnet: ${STAGE_NETWORK_IP}.0/24
                  gateway: ${STAGE_NETWORK_IP}.1

The variable is set in another file called "compose-vars.env" with STAGE_NETWORK_IP=192.168.2

But this does not work. The Error is:

ERROR: The Compose file './docker-compose.yml' is invalid because:
networks.btgnetwork.ipam.config.subnet is invalid: should use the CIDR format

I cloud not find any useful tips for that. Thank you :)

1

There are 1 best solutions below

0
On

Try to use quotes:

- subnet: "${STAGE_NETWORK_IP}.0/24" 
  gateway: "${STAGE_NETWORK_IP}.1"