What are Docker Compose profiles good for?
Experience Level: Senior
Tags: Docker Compose
Answer
You can assign Docker Compose services to profiles. Later when you are starting services, you can define which profile to use. If you pass a profile, only services that belong to a specified profile will be used.
version: "3.9"
services:
frontend:
image: frontend
profiles: ["frontend"]
healthcheck:
image: busybox
profiles: ["frontend"]
phpmyadmin:
image: phpmyadmin
depends_on:
- db
profiles:
- debug
Here the services frontend and healthcheck are assigned to the profiles frontend. You can run services from this profile by running the following command:
docker compose --profile frontend up
Related Docker Compose job interview questions
What are links in Docker Compose?
Docker Compose SeniorHow can you run a one off command using Docker Compose?
Docker Compose SeniorHow can you define what labels will be used for an image built using Docker Compose?
Docker Compose SeniorHow can you override a command that will be executed in a container of a specific service in Docker Compose?
Docker Compose SeniorHow do you map ports to a specific service container in Docker Compose?
Docker Compose Senior