Docker Compose Complete Guide | Multi-Container Apps
이 글의 핵심
This guide explains how to run and manage multi-container applications with Docker Compose—service definitions, networking, volumes, environment variables, health checks, and production-oriented Compose files—with practical YAML and shell examples.
What this post covers
This is a complete guide to managing multi-container applications with Docker Compose. It walks through service definitions, networks, volumes, environment variables, and production-oriented settings—with practical examples.
From the field: Standardizing development on Docker Compose cut onboarding from three days to about thirty minutes for our team and eliminated “works on my machine” issues entirely.
Introduction: “Setting up the dev environment is painful”
Real-world scenarios
Scenario 1: Installing PostgreSQL and Redis is tedious
You have to install and configure each one separately. Docker Compose runs them together in one shot.
Scenario 2: Everyone on the team has a different environment
Versions and settings diverge. Docker Compose keeps things consistent.
Scenario 3: You run multiple containers by hand
You run docker run over and over. Docker Compose runs the stack with a single command.
1. What is Docker Compose?
Key characteristics
Docker Compose is a tool for defining and running multi-container Docker applications.
Main benefits:
- Simple configuration: a single YAML file
- One-command startup:
docker compose up - Automatic networking: communication between containers
- Volume management: data persistence
- Environment variables:
.envfile support
2. Installation
Run the following commands in your terminal.
# Docker Desktop (Windows, macOS)
# Includes Docker Compose
# Linux
sudo apt install docker-compose-plugin
# Verify
docker compose version
3. Basics
docker-compose.yml
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb
volumes:
- postgres-data:/var/lib/postgresql/data
volumes:
postgres-data:
Commands
# Start
docker compose up
# Run in the background
docker compose up -d
# Stop
docker compose down
# View logs
docker compose logs
# Logs for a specific service
docker compose logs web
# Restart
docker compose restart
4. Hands-on example: full-stack app
Sample configuration.
# docker-compose.yml
version: '3.8'
services:
# Frontend (React)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- REACT_APP_API_URL=http://localhost:8000
depends_on:
- backend
# Backend (FastAPI)
backend:
build:
context: ./backend
dockerfile: Dockerfile
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql://postgres:secret@db:5432/mydb
- REDIS_URL=redis://redis:6379
depends_on:
- db
- redis
volumes:
- ./backend:/app
# Database (PostgreSQL)
db:
image: postgres:16
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
# Cache (Redis)
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis-data:/data
# Nginx (Reverse Proxy)
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- frontend
- backend
volumes:
postgres-data:
redis-data:
networks:
default:
name: myapp-network
5. Environment variables
.env file
# .env
POSTGRES_USER=postgres
POSTGRES_PASSWORD=secret
POSTGRES_DB=mydb
REDIS_PASSWORD=redis-secret
API_PORT=8000
FRONTEND_PORT=3000
Usage
# docker-compose.yml
services:
db:
image: postgres:16
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
6. Networking
Custom networks
services:
frontend:
networks:
- frontend-network
backend:
networks:
- frontend-network
- backend-network
db:
networks:
- backend-network
networks:
frontend-network:
backend-network:
7. Health checks
Sample configuration.
services:
backend:
image: myapp/backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
8. Production settings
docker-compose.prod.yml
version: '3.8'
services:
backend:
image: myapp/backend:1.0.0
restart: always
environment:
- NODE_ENV=production
deploy:
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
db:
image: postgres:16
restart: always
volumes:
- /data/postgres:/var/lib/postgresql/data
# Production run
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Connecting to job search and interviews
Experience standardizing local and staging environments with Compose fits well into onboarding and collaboration stories. Pair it with the portfolio and teamwork sections in the [developer job hunting guide](/en/blog/developer-job-hunting-practical-tips/, and for practical assignment prep see the [coding test strategy guide](/en/blog/coding-test-strategy-guide/.
Summary and checklist
Key takeaways
- Docker Compose: manage multi-container applications
- Simple configuration: YAML file
- Networking: created automatically
- Volumes: data persistence
- Environment variables:
.envfile - Health checks: automatic recovery
Implementation checklist
- Write
docker-compose.yml - Define services
- Configure networks
- Configure volumes
- Manage environment variables
- Implement health checks
- Production settings
Further reading
- [Kubernetes practical guide](/en/blog/kubernetes-practical-guide/
- [GitHub Actions CI/CD guide](/en/blog/github-actions-ci-cd-guide/
- [Terraform practical guide](/en/blog/terraform-practical-guide/
Keywords in this post
Docker, Docker Compose, Container, DevOps, Microservices, Infrastructure
Frequently asked questions (FAQ)
Q. Docker Compose vs Kubernetes—which should I use?
A. Docker Compose targets a single host. Kubernetes targets clusters. Prefer Docker Compose for small setups and Kubernetes for large-scale orchestration.
Q. Is it OK to use Docker Compose in production?
A. It can work for small applications, but for large-scale production, Kubernetes is usually the better fit.
Q. What is the difference between Swarm and Compose?
A. Swarm is an orchestration platform. Compose is primarily a development workflow tool. For production orchestration, use Swarm or Kubernetes.
Q. Where is volume data stored?
A. Docker stores it in Docker-managed directories on the host. Inspect with docker volume inspect <volume_name>.
자주 묻는 질문 (FAQ)
Q. 이 내용을 실무에서 언제 쓰나요?
A. Full guide to multi-container apps with Docker Compose: services, networks, volumes, environment variables, and producti… 실무에서는 위 본문의 예제와 선택 가이드를 참고해 적용하면 됩니다.
Q. 선행으로 읽으면 좋은 글은?
A. 각 글 하단의 이전 글 또는 관련 글 링크를 따라가면 순서대로 배울 수 있습니다. C++ 시리즈 목차에서 전체 흐름을 확인할 수 있습니다.
Q. 더 깊이 공부하려면?
A. cppreference와 해당 라이브러리 공식 문서를 참고하세요. 글 말미의 참고 자료 링크도 활용하면 좋습니다.
같이 보면 좋은 글 (내부 링크)
이 주제와 연결되는 다른 글입니다.
- [Kubernetes Practical Guide | Pods· Deployments](/en/blog/kubernetes-practical-guide/
- [GitHub Actions CI/CD Guide | Workflows· Secrets](/en/blog/github-actions-ci-cd-guide/
- [Developer Job Hunting Guide | Resume· Portfolio](/en/blog/developer-job-hunting-practical-tips/
- [Coding Test Complete Preparation Complete Guide](/en/blog/coding-test-strategy-guide/
이 글에서 다루는 키워드 (관련 검색어)
Docker, Docker Compose, Container, DevOps, Microservices, Infrastructure 등으로 검색하시면 이 글이 도움이 됩니다.