Docker Compose - multi-container deployments

Docker - Overview and how to use it

2 min read

Published Jul 13 2025, updated Aug 17 2026


12
0
0
0

CLIContainersDevOpsDockerImagesNetworksVolumes

Docker Compose is a tool for defining and running multi-container Docker applications using a single declarative YAML file. Instead of managing individual containers manually, Compose allows you to orchestrate multiple services like databases, APIs, and frontends with a single command.

With Docker Compose, you can:

  • Spin up multiple containers together (docker compose up)
  • Configure volumes, networks, and dependencies
  • Easily replicate complex environments locally or in CI/CD


Docker compose file

An example compose file, which is a yml format:

docker-compose.yml
version: '3.9'  # Always use the latest stable versionservices:  app:    build: .    ports:      - "3000:3000"    volumes:      - .:/app    environment:      - NODE_ENV=development    depends_on:      - db  db:    image: postgres:15    restart: always    environment:      POSTGRES_USER: myuser      POSTGRES_PASSWORD: mypass      POSTGRES_DB: mydb    volumes:      - pgdata:/var/lib/postgresql/datavolumes:  pgdata:

Breakdown:

  • services: defines each container (app, db, etc.)
  • build: builds from a local Dockerfile
  • ports: maps container ports to the host
  • volumes: mounts host folders or named volumes
  • depends_on: ensures services start in the correct order
  • environment: passes env variables to containers

You define network and volumes at the file level, eg:

networks:  backend:

And then assign them to the service, eg:

services:  api:    networks:      - backend



Running a compose file

docker compose up

Assumes the compose file is docker-compose.yml in the current directory, will start a container for each of the services.


docker compose -f custom-file.yml up

This allows you to specify the name of the compose file, if not using the default docker-compose.yml file.


You can specify the --build option when running docker compose, to rebuild the images as part of starting the compose.




Viewing compose logs

docker compose logs -f

Viewing logs for all services.


docker compose logs db

Viewing logs for a specific service.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact