docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.83k stars 5.21k forks source link

[BUG] Overwriting labels no longer working on v2.24.2 #11417

Closed crwenner closed 8 months ago

crwenner commented 8 months ago

Description

There appears to be an issue with overriding labels with the new compose version. I am getting the following error:

cannot override services.app.labels

This is happening in our linux environment, and does not happen when we revert to the previous version 2.23.3.

Steps To Reproduce

Simplified docker-compose.yml file:

version: "3.7"

services:
  app: 
    labels:
      sqm.app: "foo-name"

Simplified docker-compose.override.yml file:

version: "3.7"

services:
  app:
    labels:
      - "traefik.docker.network=sqm_default"
      - "traefik.port=80"

Running the following command:

docker compose -f docker-compose.yml -f docker-compose.override.yml up -d

Produces this error while running v2.24.2 compose: cannot override services.app.labels

Compose Version

Docker Compose version v2.24.2

Docker Environment

Client: Docker Engine - Community
 Version:    25.0.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Anything else?

No response

bbbiirdy commented 8 months ago

To provide some extra detail:

It seems to be the merging of array / dictionary labels that is the issue. When I altered the overrides to be in the same format as the initial labels field it did not exhibit the error. It also affects 2.24.1.

ndeloof commented 8 months ago

This regression is covered by https://github.com/compose-spec/compose-go/pull/548

gjwnc commented 8 months ago

I just wanted to mention our use case causing issues since the upgarde. We have a Makefile based setup, where we combine multiple compose yaml files to get the final services for development vs production, e.g. something like docker compose -f docker-compose.root.yaml -f docker-compose.database.yaml -f docker-compose.proxy.yaml -f docker-compose.[SOMEENV].override.yaml
To have a default proxy route for our container we use a labels syntax like

services:
  web:
    labels:
      - "traefik.http.routers.${PROJECT_NAME}-http.rule=HostRegexp(`${PROJECT_NAME}.{ip:.*}.traefik.me`)"

This is useful for first time setup and in case someone else breaks the project config.

Other override files then use different labels like

traefik.http.routers.api-https-admin-api.middlewares: basic-auth@file,gzip@file

The main reason for this mixing of syntax of labels is because compose cannot interpolate key's in yaml files, mentioned here.