指南

VPS에서 프로덕션 Docker Compose 스택

중급25분 읽기업데이트됨 2026년 6월 27일
간단한 답변

작동 가능한 프로덕션 스택은 자동 TLS를 위한 Caddy, 애플리케이션, PostgreSQL 및 Redis로 구성되며, 하나의 Compose 파일에 명명된 볼륨과 상태 확인이 정의됩니다. 8GB RAM과 NVMe에서 이는 상당한 트래픽을 처리하며, 배포 전 스냅샷은 롤백을 2분 작업으로 만듭니다.

01 공식 저장소에서 Docker 설치

Distribution packages lag significantly. The convenience script is fine on a fresh instance.

curl -fsSL https://get.docker.com | sh
systemctl enable --now docker

02 Compose 파일 작성

Caddy obtains and renews certificates automatically, which removes the single most common source of production breakage.

services:
  caddy:
    image: caddy:2-alpine
    restart: unless-stopped
    ports: ["80:80", "443:443", "443:443/udp"]
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
  app:
    build: .
    restart: unless-stopped
    depends_on: { db: { condition: service_healthy } }
    environment:
      DATABASE_URL: postgres://app:${DB_PASS}@db:5432/app
  db:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: ${DB_PASS}
    volumes: [pgdata:/var/lib/postgresql/data]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
      interval: 10s
volumes: { caddy_data: {}, pgdata: {} }

03 Caddy 구성

Three lines is a complete TLS-terminating reverse proxy with automatic certificate renewal.

app.example.com {
  encode zstd gzip
  reverse_proxy app:8000
}

04 컨테이너가 아닌 데이터베이스를 백업

A file copy of a running Postgres data directory produces a corrupt backup that appears to succeed. Dump it properly.

docker compose exec -T db pg_dump -U app app | zstd > /backups/app-$(date +%F).sql.zst

05 배포 전 스냅샷

Free, instant, and it converts a failed deployment from an incident into a rollback.

자주 묻는 질문

이에 필요한 RAM은 얼마인가요?

컨테이너 메모리 제한을 합산하고 호스트용으로 약 1GB를 추가하세요. 이 스택은 8GB에서 충분합니다.

Docker Swarm이나 Kubernetes를 대신 사용해야 하나요?

단일 서버에는 필요 없습니다. 실제로 노드가 둘 이상이 될 때까지 Compose가 올바른 도구입니다.