What is Docker Compose profiles?
Why Interviewers Ask This
Mid-level Docker roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
Docker Compose profiles allow you to selectively start services, enabling different configurations for different scenarios within the same Compose file. Services can be assigned to one or more profiles; services without a profile are always started. Assign profiles in compose.yml: services:\n web:\n image: myapp\n # no profile — always starts\n debug-proxy:\n image: mitmproxy\n profiles: [debug]\n mail-dev:\n image: mailhog\n profiles: [dev, testing]\n monitoring:\n image: prometheus\n profiles: [monitoring]. Activate profiles: docker compose --profile debug up — starts web + debug-proxy; docker compose --profile dev --profile monitoring up — starts web + mail-dev + monitoring. Set via env var: COMPOSE_PROFILES=debug,monitoring docker compose up. Use cases: (1) Debug services only started when debugging; (2) Third-party mocks (email, SMS) only in dev; (3) Monitoring stack only when needed; (4) Database admin UIs (pgAdmin, phpMyAdmin) only in development; (5) Load testing tools activated on demand. Profiles allow a single compose.yml to serve multiple purposes without maintaining separate files or commenting out services.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Docker experience.
Previous
What is the principle of least privilege in Docker?
Next
What is the difference between COPY and RUN in terms of Docker layers?