Docker Compose - multi-container deployments

Docker - Overview and how to use it

2 min read

Published Jul 13 2025


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 version

services:
  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/data

volumes:
  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.


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact