How to run multi-service applications with Docker Compose?

· Category: Docker

Short answer

Use docker compose up to start all services defined in your Compose file. Add -d to run in detached mode and --build to rebuild images before starting containers.

Steps

  1. Ensure docker-compose.yml is in the current directory.
  2. Run docker compose up -d to start all services in the background.
  3. View logs with docker compose logs -f.
  4. Stop services with docker compose down.

Example

docker compose up -d

Rebuild and start:

docker compose up -d --build

Start a specific service:

docker compose up -d web

Tips

  • Use --remove-orphans to clean up containers for services no longer defined.
  • Use --scale web=3 to run multiple instances of a service.
  • Use docker compose ps to see the status of all services.

Common issues

  • Services may fail if they depend on a database that is not yet ready; use health checks.
  • Port conflicts occur when multiple Compose projects try to bind the same host port.
  • Stale containers from previous runs can cause unexpected behavior; run docker compose down first.