DEV Community

Cover image for Using Profiles with Docker Compose
Pradumna Saraf
Pradumna Saraf

Posted on

Using Profiles with Docker Compose

In this setup, the backend, frontend, and database form the core of the application and are started by default because we didn't assign any profiles to them.

Prometheus and Grafana are grouped under the monitoring profile, as we only need them if we want to look at the metrics or performance. About phpMyAdmin, it is grouped under the debug profile, and it’s only necessary when we need to debug database issues.

So, by default, only the core services start and the monitoring and debugging tools are turned off.

docker compose up
Enter fullscreen mode Exit fullscreen mode

When we need monitoring and debugging, we can start the services by using the --profile flag.

docker compose --profile monitoring up # to start monitoring tools
docker compose --profile debug up # to start debugging tools
Enter fullscreen mode Exit fullscreen mode

We can also combine the profiles to start multiple services at once:

docker compose --profile monitoring --profile debug up
Enter fullscreen mode Exit fullscreen mode

That’s it. This approach keeps your Compose file clean, avoids running unnecessary services.

As always, I'm glad you made it to the end. Thank you for your support and reading. I regularly share tips on Twitter (It will always be Twitter ;)). You can connect with me there.

Top comments (0)