Is there any way to place a variable name as the creation of a network?..
docs
the reason why I want to do it, is that the same project is mounted on the same server of “developers” (not in production) and each one has its isolated development environment, I would like to use the same YML file and only change one environment variable, instead of everyone having to modify their YML files, avoid that by accident they commits with their particular configurations.
when creating a network with key: net_$COMPOSE_PROJECT_NAME_stable_internal
is taken literally and there is no substitution of environment variables
however in the part of:
networks:
- net_${COMPOSE_PROJECT_NAME}_stable_internal
If the substitution is done correctly, I guess it’s because it’s not a “key” if it’s not a “value”, And so here if you apply in the right way
when running the comanto I get the following error
$ docker-compose pull
WARNING: Some networks were defined but are not used by any service: net_$COMPOSE_PROJECT_NAME_stable_outside, net_$COMPOSE_PROJECT_NAME_stable_internal
ERROR: Service “php” uses an undefined network “net_PROJECT-NAME-EXAMPLE_stable_internal”
this is an example of the YML file
version: "3.7"
services:
php:
image: php:7.2-fpm-alpine
networks:
- net_${COMPOSE_PROJECT_NAME}_stable_internal
db:
image: percona:5.7
ports:
- ${DB_PORT_EXPOSED}:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
networks:
- net_${COMPOSE_PROJECT_NAME}_stable_internal
restart: always
nginx:
image: nginx:stable
- ../appication:/var/www/html
networks:
- net_${COMPOSE_PROJECT_NAME}_stable_outside
- net_${COMPOSE_PROJECT_NAME}_stable_internal
restart: always
networks:
# ----- ᛎᛎᛎᛎᛎᛎᛎᛎᛎᛎᛎᛎᛎ this is the part that doesn't work the change of variable
net_${COMPOSE_PROJECT_NAME}_stable_outside:
external:
name: ${DOCKER_NETWORK}
net_${COMPOSE_PROJECT_NAME}_stable_internal:
driver: bridge