Why
A database admin panel, backup job, or migration runs only occasionally, yet it works against the same stack: same
network, same database. Defined as regular services, they start on every up -d: a database panel stays exposed around
the clock, and the backup runs on every update. A profile keeps them in the file but off by default.
How to write it
services:
db:
image: mariadb:11.8
# …
adminer:
image: adminer:5
profiles: [tools]
ports: ["127.0.0.1:8082:8080"]
backup:
image: mariadb:11.8
profiles: [tools]
# command: database dump — see link below
A service without profiles always starts; one with profiles starts only when the profile is enabled or the service
is named explicitly:
| Command | What it does |
|---|---|
docker compose up -d |
starts everything except profile services |
docker compose up -d adminer |
starts adminer — naming the service enables its profile automatically |
docker compose run --rm backup |
one-off run; deletes the container on exit |
docker compose --profile tools up -d |
starts everything together with the tools profile |
docker compose stop adminer |
stops only adminer |
docker compose --profile '*' down |
stops and removes everything, profiles included |
Use run --rm for one-off jobs: backups, migrations, checks. The container gets the stack’s networks, volumes, and
variables, prints output to the terminal, and removes itself. The MariaDB dump command is in MariaDB in a container.
If a server should always run a profile — say, a test machine with adminer — put COMPOSE_PROFILES=tools in .env so
Compose enables it without a flag.
If it doesn’t work
docker compose down finished, yet adminer is still running and output says Resource is still in use
- Cause
downwithout a profile doesn't touch profile services. Neither does--remove-orphans: those services are defined in the file, so they aren't orphans.- Fix
- Run
docker compose --profile '*' downto stop everything including profiles, ordocker compose stop adminerif the rest should stay up.
up -d: service "app" depends on undefined service "adminer": invalid compose project
- Cause
- A service without a profile depends on a service in a profile. Until that profile is enabled, Compose treats the second service as absent.
- Fix
- Remove
depends_onpointing to the utility service: the main stack shouldn't depend on it.
How to check
Check which services a plain up -d will start and which profiles exist in the file:
docker compose config --services
# db
docker compose config --profiles
# tools
Utility services should not show up in the first list.