-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Description
It would be very useful if Docker Compose supported a true "default" profile for services. The idea is:
A service with a "default" profile would be started if no profiles are specified via --profile on the CLI.
If any profile is specified, services with the "default" profile would not be started, unless explicitly included in the profile list.
Current behavior:
There is a workaround where setting profiles: [""] causes a service to be started by default when no profile is given, but not when any profile is specified. I have tested this on Docker Desktop for Mac (v2.39.2-desktop.1) and it works. However, there are StackOverflow discussions suggesting this does not work reliably across all platforms or Compose versions.
Desired behavior:
Add first-class support for a "default" (or similar) profile in Docker Compose. Services tagged with this profile would start only when no profile is specified, and not when any profile is given. This would make configuration more explicit and portable, and avoid reliance on undocumented/undocumented "profiles: [""]" workarounds.
Workaround working on MacOS
services:
service1:
image: busybox
container_name: service1
command: ["sleep", "3600"]
# No profile, always starts by default
service2:
image: busybox
container_name: service2
command: ["sleep", "3600"]
profiles: ["foo", ""]
service3:
image: busybox
container_name: service3
command: ["sleep", "3600"]
profiles: ["bar"]
Test 1:
[~/developer/test]$ docker compose up -d
[+] Running 3/3
✔ Network test_default Created 0.0s
✔ Container service1 Started 0.1s
✔ Container service2 Started
Test 2:
[~/developer/test]$ docker compose --profile bar up -d
[+] Running 3/3
✔ Network test_default Created 0.0s
✔ Container service3 Started 0.1s
✔ Container service1 Started