Skip to main content

Command Palette

Search for a command to run...

How to Use Docker Compose Profiles

Updated
2 min read
How to Use Docker Compose Profiles

I recently discovered Docker compose profiles and wanted to share it as it can be useful to someone else.

Docker Compose profiles let you control which services run without modifying your docker-compose.yml. They’re useful for separating optional services (like monitoring tools or debugging containers) from your core stack.

From Docker documentation:
Profiles help you adjust your Compose application for different environments or use cases by selectively activating services. Services can be assigned to one or more profiles; unassigned services start/stop by default, while assigned ones only start/stop when their profile is active. This setup means specific services, like those for debugging or development, can be included in a single compose.yml file and activated only as needed.

How to use profiles in your docker-compose.yml

1. Add Profiles to Your Compose File

In your docker-compose.yml, specify the profiles key for optional services:

services:
  app:
    container_name: my-app
    image: myapp:latest
    ports:
      - "8080:8080"

  db:
    container_name: pg-database
    image: postgres:15

  adminer:
    container_name: adminer
    image: adminer
    ports:
      - "8081:8080"
    profiles:
            - debug

Here, adminer is tagged with the debug profile, while app and db always run.

2. Start Services with a Profile

Run only the default services:

docker compose up

Run services including the debug profile:

docker compose --profile debug up

That’s it !
You can now use profiles to load your local dev tools only when you need them.

J

Ha, just yesterday I discovered the same thing 👍🏼

1