compose icon indicating copy to clipboard operation
compose copied to clipboard

add support for variable interpolation in depends_on

Open lovasoa opened this issue 2 years ago • 0 comments

Description

I have a basic web service (sqlpage) that can use any one of multiple databases. I can choose which database to use by setting the environment variable COMPOSE_PROFILES.

My docker-compose.yml looks like that:

services:
  web:
    build: { context: "." }
    ports:
      - "8080:8080"
    volumes:
      - .:/var/www
    depends_on:
      "${COMPOSE_PROFILES-postgres}": # <- does not work
        condition: service_healthy
    environment:
      DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:Password123!@${COMPOSE_PROFILES:-postgres}/sqlpage

Unfortunately, that doesn't work because variable interpolation works only on values, not keys, in the yaml definition. It would be nice if we could have variable interpolation here, or an alternative syntax for depends_on like

    depends_on:
         - service: "${COMPOSE_PROFILES-postgres}"
           condition: service_healthy

lovasoa avatar Jul 30 '23 10:07 lovasoa