You have three microservices: a frontend, a backend API, and a database. You want to run them locally using Docker Compose. Which of the following docker-compose.yml snippets correctly defines the services with proper network and volume setup for local development?
Check how services communicate using service names and how volumes are defined for persistent data.
Option A correctly uses service names for database connection (db), defines volumes for data persistence, and sets dependencies so services start in order. Options C and D incorrectly use localhost in the backend environment, which won't resolve inside Docker network. Option A uses version 2 and lacks proper build context and network setup.
You want to test how your backend service handles multiple instances locally using Docker Compose. Which command correctly scales the backend service to 3 instances?
Remember the modern syntax for scaling services with docker-compose up.
The correct command is docker-compose up --scale backend=3. The scale command is deprecated. The run command does not support scaling.
Which of the following is a common tradeoff when using Docker Compose for local development of microservices?
Think about differences between local and production environments.
Docker Compose is great for local setups but does not fully replicate production environments, especially in networking and scaling. It requires configuration files and environment variables. Scaling is manual and limited.
In Docker Compose, what does the depends_on key do when defined between services?
Consider what depends_on controls in startup order versus readiness.
The depends_on key controls startup order but does not wait for the dependent service to be fully ready or healthy. Health checks require additional configuration.
You plan to run 5 microservices locally with Docker Compose. Each service requires approximately 500MB RAM and 0.5 CPU cores. Your laptop has 8 CPU cores and 16GB RAM. Considering Docker and OS overhead, what is the maximum number of service instances you can run simultaneously without swapping or CPU throttling?
Calculate max instances by RAM and CPU separately, then take the smaller number.
RAM allows 32 instances (16GB / 0.5GB). CPU allows 16 instances (8 cores * 2 instances per core). Considering overhead, the limiting factor is CPU, so max is 16 instances.