Docker Compose v2 introduces profiles, file watching for development, and improved healthcheck configurations. Mastering these features enables efficient local development environments and robust multi-container application management.
0 / 5 completed
1 / 5
A Docker Compose file defines profiles: ["debug"] on a service. When does this service start?
Services with profiles: defined are only started when that profile is explicitly activated via --profile debug or COMPOSE_PROFILES=debug. Services without a profile always start. Profiles enable optional services (debug tools, test databases, admin UIs) that shouldn't run in every environment.
2 / 5
What does develop: watch: in Docker Compose v2 enable for a service?
Docker Compose develop.watch defines file watching rules for development: sync action copies changed files into the running container without rebuilding (like bind mounts but selective); rebuild action triggers a full image rebuild and service restart. This eliminates manual docker compose up --build cycles during development.
3 / 5
A Compose service defines healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/health"] interval: 30s retries: 3 start_period: 40s. What does start_period do?
start_period defines a grace period after container start during which health check failures are not counted toward the retry limit. The health check still runs during this period, but failures are tolerated. This prevents containers with legitimate slow startup (database initialization, cache warming) from being marked unhealthy prematurely.
4 / 5
What is the key difference between using volumes: - ./src:/app/src (bind mount) versus develop: watch: - path: ./src target: /app/src action: sync?
While bind mounts provide full bidirectional real-time sync of everything, develop.watch with sync action provides selective unidirectional sync from host to container, respecting ignore patterns (e.g., excluding node_modules). This prevents syncing large directories and works better on macOS/Windows where bind mount performance is poor.
5 / 5
A developer runs docker compose up --scale worker=3. What constraint must the worker service meet for this to work without errors?
Scaling a service with --scale creates multiple containers. If the service maps a fixed host port (e.g., ports: - "8080:8080"), only one container can bind that port — others fail. The solution is to either omit the host port (use only expose: 8080 for container-to-container communication) or use dynamic ports (ports: - "8080" without a host port).