docker-archive / compose-cli

Easily run your Compose application to the cloud with compose-cli
Apache License 2.0
955 stars 253 forks source link

Docker compose CLI ignores `--profile` selection #1660

Closed andy-rash closed 3 years ago

andy-rash commented 3 years ago

Description

Docker Compose CLI ignores service profiles, instead starting up all services in docker-compose.yml.

This issue has been reported very recently, and a fix appears to have been included in the latest release (v1.0.14). However, this doesn't seem to have fixed the issue.

I noticed this problem after updating the Compose CLI as part of updating Docker Desktop for Mac. This issue does not appear in Docker Desktop v3.3.1 (i.e., the version right before Compose CLI v1.0.14 was introduced).

Profile Table

Service Profile
api prod
mock-api dev
dev-database dev
web prod

Steps to reproduce the issue:

  1. Run docker compose --profile dev up or docker compose --profile prod up.

docker-compose.yml

version: '3.9'

services:
  api:
    build: .
    command: ["${DOCKER_CONTAINER_PROJECT_ROOT}/scripts/start.sh"]
    env_file:
      - ./.env
    environment:
      PYTHONPATH: ${DOCKER_CONTAINER_PROJECT_ROOT}
    restart: always
    volumes:
      - ./:${DOCKER_CONTAINER_PROJECT_ROOT}
    working_dir: ${DOCKER_CONTAINER_PROJECT_ROOT}
    profiles: ["prod"]

  mock-api:
    build: .
    command: ["${DOCKER_CONTAINER_PROJECT_ROOT}/scripts/start.sh"]
    depends_on:
      - dev-database
    env_file:
      - ./.env.dev
    environment:
      DEV_MODE: "true"
      PYTHONPATH: ${DOCKER_CONTAINER_PROJECT_ROOT}
    ports:
      - "8000:8080"
    restart: always
    volumes:
      - ./:${DOCKER_CONTAINER_PROJECT_ROOT}
    working_dir: ${DOCKER_CONTAINER_PROJECT_ROOT}
    profiles: ["dev"]

  dev-database:
    image: postgres:12.5
    env_file:
      - .env.dev
    ports:
      - "5432:5432"
    restart: always
    volumes:
      - dev-db-data:/var/lib/postgresql/data
    profiles: ["dev"]

  web:
    depends_on:
      - api
    image: caddy:2.3.0-alpine
    ports:
      - "80:80"
      - "443:443"
    profiles: ["prod"]
    restart: unless-stopped
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
      - caddy-config:/config

volumes:
  caddy-data:
  caddy-config:
  dev-db-data:

Describe the results you received:

Result from docker compose --profile dev up.

❯ docker compose --profile dev up
[+] Running 4/4
 ⠿ Container transcription_dev-database_1  Created      0.0s
 ⠿ Container transcription_api_1           Created      0.0s
 ⠿ Container transcription_mock-api_1      Created      0.0s
 ⠿ Container transcription_web_1           Created      0.0s

Describe the results you expected:

Result from docker compose --profile dev up.

❯ docker compose --profile dev up
[+] Running 2/2
 ⠿ Container transcription_dev-database_1  Created      0.0s
 ⠿ Container transcription_mock-api_1      Created      0.0s

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Cloud integration: 1.0.14
 Version:           20.10.6
 API version:       1.41
 Go version:        go1.16.3
 Git commit:        370c289
 Built:             Fri Apr  9 22:46:57 2021
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.6
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8728dd2
  Built:            Fri Apr  9 22:44:13 2021
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker context show:
You can also run docker context inspect context-name to give us more details but don't forget to remove sensitive content.

default

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  compose: Docker Compose (Docker Inc., 2.0.0-beta.1)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 4
  Running: 0
  Paused: 0
  Stopped: 4
 Images: 3
 Server Version: 20.10.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.25-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 1.942GiB
 Name: docker-desktop
 ID: ELFE:2ZBI:HXNV:CJT4:437M:LSQK:NT6D:7QQZ:SLQU:WGAA:J3NT:5O4U
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details (AWS ECS, Azure ACI, local, etc.):

macOS Big Sur (v11.3.1, build 20E241), running on Apple Silicon

Compose CLI installed as part of Docker Desktop for Mac

everton-nasc commented 3 years ago

Looks like the fix will be placed along with the version 1.0.15

https://github.com/docker/compose-cli/blob/v1.0.15/cli/cmd/compose/compose.go#L123

andy-rash commented 3 years ago

Looks like the fix will be placed along with the version 1.0.15

https://github.com/docker/compose-cli/blob/v1.0.15/cli/cmd/compose/compose.go#L123

Well that would just make too much sense, wouldn't it? I could've sworn I saw that fix under the v1.0.14 tag when I looked yesterday, but I guess I was mistaken. Thanks for catching that!