Docker Docker ComposeMulti-Container Apps

Article & Tutorial

Docker Compose Beginner Guide: Run Multi-Container Apps with compose.yaml

Build multi-container applications with compose.yaml, services, ports, environment variables, volumes, networks, dependencies, and essential Compose commands.

Docker Compose services in a multi-container application
Docker Compose services in a multi-container application
Contents

Docker Compose Beginner Guide

Docker Compose helps you define and run multi-container applications using a single YAML file. This guide explains services, ports, volumes, networks, environment variables, commands, and beginner examples.

What is Docker Compose?

Docker Compose lets you describe multiple services in a compose.yaml file and start them together with one command.

Basic compose.yaml

services: web: image: nginx:alpine ports: - "8080:80"

Run the app

docker compose up -d docker compose ps docker compose logs web docker compose down

App with database example

services: app: image: node:20-alpine working_dir: /app volumes: - .:/app command: sh -c "npm install && npm start" ports: - "3000:3000" environment: DATABASE_HOST: db depends_on: - db db: image: postgres:16 environment: POSTGRES_DB: appdb POSTGRES_USER: appuser POSTGRES_PASSWORD: example volumes: - db_data:/var/lib/postgresql/data volumes: db_data:

Important Compose concepts

  • services define containers.
  • ports publish container ports to the host.
  • volumes persist data or mount local files.
  • environment passes environment variables.
  • depends_on controls startup order, not full readiness.
  • Service names become DNS names inside the Compose network.

Useful commands

docker compose up docker compose up -d docker compose down docker compose logs -f docker compose ps docker compose exec app sh docker compose pull docker compose build

Common mistakes

  • Thinking depends_on means the database is fully ready.
  • Committing real passwords in compose files.
  • Forgetting named volumes for database data.
  • Using Compose production files without reviewing secrets and ports.
  • Not checking logs when services fail.

Best practices

  • Use Compose for local development and small environments.
  • Use named volumes for database state.
  • Use .env carefully and do not commit secret values.
  • Keep service names clear.
  • Use separate override files for local-only settings.

Related Melochip guides

  • Docker Learning Path
  • Docker Volumes Explained
  • Docker Networks Explained

Official references

  • Docker Compose documentation
  • Compose file reference

Did this help?

Yes No

Join the discussion

0 Comments

Ask questions, add context, or share what worked.

Sign in to join the discussion

No comments yet. Start the discussion.

More from Melochip Editorial

Related articles

Stay in the loop. Get new Melochip articles

Receive Melochip article updates when new articles are available. Explicit opt-in only.

No pre-checked boxes. Unsubscribe support is part of the subscriber foundation.