Docker Compose Profiles: Organize Your Development Environments
Learn how to use Docker Compose profiles to selectively start service subsets, keeping your development environment clean and efficient.

Previously in this course, we explored finalizing your Docker project structure and mastered scaling services to handle load. As your project grows, you might find that you don't always need every component—like a heavy background worker or a secondary database—running during every coding session.
This lesson introduces Docker Compose profiles, a feature that allows you to tag services and launch only what you need, significantly reducing resource overhead and keeping your workspace tidy.
Understanding Docker Compose Profiles
In a complex project, your docker-compose.yml file often defines the entire production-ready stack. However, when you are simply working on the frontend or a specific API service, running the full stack can be overkill.
Profiles allow you to assign one or more "tags" to a service. When you start your containers, you can tell Docker to only include services assigned to specific profiles. If no profile is specified, Docker Compose only starts services that have no profile assigned (or those marked as "always on").
Why Use Profiles?
- Resource Efficiency: Keep your laptop cool by not running services you aren't currently developing.
- Environment Parity: Keep your "debug" tools (like an admin UI or a monitoring dashboard) defined in the same file as your app, but only enabled when you need them.
- Simplified Onboarding: Allow new developers to start a "minimal" stack by default while keeping "full" stack options available via a single flag.
Working Example: Selective Service Startup

Imagine our running project involves a web app, a primary database, and a heavy-duty data analysis service that we only need for testing. We can use profiles to keep our docker-compose.yml clean.
YAMLservices: web: image: my-web-app:latest ports: - "8080:80" db: image: postgres:15 # This service only runs when we explicitly ask for it analytics-engine: image: my-analytics-worker:latest profiles: - tools depends_on: - db
Starting Services by Profile
By default, running docker compose up will start web and db, but not analytics-engine because it is hidden behind the tools profile.
To include the analytics engine, you pass the --profile flag:
Bashdocker compose --profile tools up
You can also use the COMPOSE_PROFILES environment variable if you want to set a default for your shell session:
Bashexport COMPOSE_PROFILES=tools docker compose up
Hands-on Exercise
- Open your current project's
docker-compose.yml. - Add a
profilesblock to one of your auxiliary services (like a cache or a documentation generator). - Run
docker compose upand verify that the service is excluded from the startup logs. - Run
docker compose --profile <your-profile-name> upand confirm that the service starts as expected.
Common Pitfalls

- Forgetting Dependencies: If
Service Adepends onService B, andService Bis in a profile that isn't active,Service Awill fail to start. Always ensure that the entire dependency chain is reachable. - Assuming Persistence: Profiles control which containers are created and started. They do not automatically tear down or stop containers when you stop the command, unless you use the
--remove-orphansflag or manage them explicitly. - Over-complicating: Don't create too many profiles. If a service is truly required for the app to function, it should not have a profile. Use profiles only for optional, auxiliary, or debugging tools.
FAQ
Q: Can a service belong to multiple profiles?
A: Yes! You can provide a list under profiles:, and the service will start if any of those profiles are requested.
Q: Do profiles affect production deployments?
A: Profiles are primarily a local development feature. If you deploy using docker compose in production, ensure your orchestration tool (like Swarm or Kubernetes) is configured to handle the service requirements explicitly, as profile flags are often ignored or not passed by CI/CD pipelines.
Q: How do I see which services are currently "active" in a profile?
A: You can run docker compose ps to see which containers are currently running, regardless of how they were started.
Recap

Docker Compose profiles provide a flexible way to manage your development environment by allowing you to toggle service groups. By defining profiles in your YAML, you save resources and improve organization. You've now seen how to move from a rigid, "all-or-nothing" stack to a modular, developer-friendly architecture.
Up next: We will explore Volume Drivers and External Storage to see how to manage persistent data outside of local bind mounts.
Work with me

CI/CD Pipeline & Docker Containerization
Ship with confidence: automated CI/CD pipelines and Docker setups so every push is tested and deployed — no more manual, error-prone releases.

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.


