Aaron Beaudoin
Aaron Beaudoin

Reputation: 587

Should the top-level `name` property in `compose.yaml` set `COMPOSE_PROJECT_NAME` for the purpose of interpolation?

Suppose I have a compose.yaml file like the following:

name: my-project
services:
  database:
    image: postgres:10
    container_name: ${COMPOSE_PROJECT_NAME}_database

I would expect my docker compose config output to look like this:

name: my-project
services:
  database:
    container_name: my-project_database
    image: postgres:10
    networks:
      default: null
networks:
  default:
    name: my-project_default

But it doesn't. It looks like this:

name: my-project
services:
  database:
    container_name: _database
    image: postgres:10
    networks:
      default: null
networks:
  default:
    name: my-project_default

The ${COMPOSE_PROJECT_NAME} in container_name isn't interpolated. At first glance, this seems to make sense, since you'd expect that syntax to be only for pulling in environment variables. But the Compose spec says this:

Whenever project name is defined by top-level name or by some custom mechanism, it MUST be exposed for interpolation and environment variable resolution as COMPOSE_PROJECT_NAME

So then am I just missing something, or is this a bug?

Upvotes: 0

Views: 4130

Answers (1)

Aaron Beaudoin
Aaron Beaudoin

Reputation: 587

It was a bug. See https://github.com/docker/compose/issues/9530.

So the answer is yes, the top-level name property in compose.yaml should set COMPOSE_PROJECT_NAME for the purpose of interpolation.

Upvotes: 3

Related Questions