docker / compose

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

[BUG] docker compose config ignores services with -profile #11907

Closed mricos closed 2 weeks ago

mricos commented 2 weeks ago

Description

Adding profiles to docker-compose.yml breaks the configuration. The same configuration without profiles works correctly.

Docker Compose Version

docker compose version
Docker Compose version v2.21.0

Environment

Additional Information

Possible Workarounds

None identified. The issue appears specific to the use of profiles in the Docker Compose configuration.

Conclusion

This bug prevents the use of profiles in Docker Compose, impacting configurations that rely on environment-specific setups.

Steps To Reproduce

Steps to Reproduce

  1. Working Example (Without Profiles)

    Create a docker-compose.yml file with the following content:

    ---
    
    services:
     nginx:
       image: nginx:latest
       container_name: nginx-test
       ports:
         - "80:80"
    
    networks:
     pxjam:
       driver: bridge

    Commands:

    docker compose config
    docker compose config --services

    Expected Output:

    services:
     nginx
  2. Broken Example (With Profiles)

    Create a docker-compose.yml file with the following content:

    ---
    
    services:
     nginx:
       image: nginx:latest
       container_name: nginx-test
       ports:
         - "80:80"
       profiles:
         - dev
    
    networks:
     pxjam:
       driver: bridge

    Commands:

    docker compose config
    docker compose config --services

    Actual Output:

    name: test
    services: {}

    Expected Output:

    services:
     nginx

Compose Version

Docker Compose version v2.21.0

Docker Environment

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

Server:
 Containers: 4
  Running: 0
  Paused: 0
  Stopped: 4
 Images: 11
 Server Version: 26.1.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d2d58213f83a351ca8f528a95fbd145f5XXXXXX
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.0-87-generic
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.918GiB
 Name: xxx-xxx-qa01
 ID: 173ce8c6-f4a4-4a2c-a198-3335f5bdeXXX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

Works without error as expected with docker-compose config

docker-compose version 1.29.2, build unknown docker-py version: 5.0.3 CPython version: 3.10.12 OpenSSL version: OpenSSL 3.0.2 15 Mar 2022

ndeloof commented 2 weeks ago

Please upgrade with latest release (v2.27.1) and confirm this issue is still relevant

ndeloof commented 2 weeks ago

AFAICT this is the expected behavior: as you declare a service with a profile, this one is excluded from model until profile is explicitly selected. This is what profiles are all about. Please note you can enable all profiles by running :

docker compose --profile="*" config