brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: put optional services behind a Compose profile

Docker
~/tips/tip-docker-compose-profiles

services:

Keeps optional services such as admin tools switched off until you ask for them by name.

Not every service in a compose file should start every time. A database admin page, a debug container or a seed job is noise on a normal run.

Give those services a profiles list. Services without one always start. Services with one stay off until you ask for them.

services:
  app:
    image: myapp
  adminer:
    image: adminer
    profiles: [debug]

A plain docker compose up -d now starts only app. When I want the extra one, I run:

docker compose --profile debug up -d

You can repeat the flag, use --profile "*" for everything, or set COMPOSE_PROFILES=debug as an environment variable instead. One detail: if you name a profiled service directly, as in docker compose up adminer, it starts even though its profile is off.

You can also keep one compose file for several situations. Put a test runner, a backup job or a monitoring container behind their own profile names and pick what you need per run. That beats three copies drifting apart.

The caveat comes when you stop things. docker compose down only touches the profiles that are active, so run it with the same --profile flag or the extra container stays behind.

Further reading: Using profiles with Compose, On this site: ${VAR:?message} makes Compose stop when a variable is missing, On this site: use docker compose exec -T when a script runs it

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link