Docker Compose: 다중 컨테이너 애플리케이션 오케스트레이션 🧩
I’m happy to translate the article for you, but I don’t have access to external sites, so I can’t retrieve the full text from the link you provided. Could you please paste the content you’d like translated (excluding any code blocks or URLs you want to keep unchanged)? Once I have the text, I’ll translate it into Korean while preserving the original formatting and markdown.
Docker Compose란? 🤔
Docker Compose는 다중 컨테이너 Docker 애플리케이션을 정의하고 실행하기 위한 도구입니다. 하나의 YAML 파일과 몇 개의 명령만으로 애플리케이션의 모든 서비스를 구성하고 한 명령으로 전체 스택을 시작할 수 있습니다.
Docker Compose를 사용하는 이유
- 단순성 – 전체 애플리케이션 스택을 하나의 파일에 정의합니다.
- 재현성 – 팀의 모든 사람이 정확히 동일한 환경을 얻습니다.
- 서비스 조정 – 컨테이너 간 자동 네트워킹.
- 환경 변수 – 손쉬운 구성 관리.
- 한 번의 명령으로 작업 – 전체 애플리케이션 스택을 시작, 중지 및 재구축합니다.
docker-compose.yml 파일 작성
기본 구조
version: '3'
services:
web:
image: nginx
ports:
- "80:80"
db:
image: postgres
environment:
POSTGRES_PASSWORD: example
- version: Compose 파일 형식 버전을 지정합니다.
- services: 생성할 컨테이너를 정의합니다.
- volumes (optional): 명명된 볼륨을 정의합니다.
- networks (optional): 사용자 정의 네트워크를 정의합니다.
서비스 정의
각 서비스는 컨테이너를 나타냅니다. 다양한 방법으로 설정할 수 있습니다:
services:
web:
image: nginx # Use an existing image
# OR
build: ./web # Build from a Dockerfile
build: # More build options
context: ./web
dockerfile: Dockerfile.dev
ports:
- "8080:80" # Port mapping
environment: # Environment variables
NODE_ENV: development
env_file: .env # Or use an env file
volumes: # Mount volumes
- ./web:/usr/share/nginx/html
depends_on: # Service dependencies
- api
restart: always # Restart policy
애플리케이션 스택 관리
전체 예시: 데이터베이스와 캐시가 포함된 웹 앱
version: '3'
services:
web:
build: ./frontend
ports:
- "3000:3000"
volumes:
- ./frontend:/app
- /app/node_modules
environment:
- REACT_APP_API_URL=http://api:5000
depends_on:
- api
api:
build: ./backend
ports:
- "5000:5000"
volumes:
- ./backend:/app
- /app/node_modules
environment:
- DB_HOST=db
- REDIS_HOST=redis
depends_on:
- db
- redis
db:
image: postgres:13
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=secretpassword
- POSTGRES_USER=myuser
- POSTGRES_DB=myapp
redis:
image: redis:alpine
volumes:
- redis-data:/data
volumes:
postgres-data:
redis-data:
이 설정에는 다음이 포함됩니다:
- React 프런트엔드
- 백엔드 API
- PostgreSQL 데이터베이스
- Redis 캐시
- 데이터를 위한 영구 볼륨
- 환경 설정
- 서비스 의존성
환경 구성
Compose 파일 내 인라인
services:
web:
environment:
- NODE_ENV=development
- API_URL=http://api:5000
.env 파일에서
services:
web:
env_file:
- ./web.env
셸 환경에서
services:
web:
environment:
- NODE_ENV
- API_KEY
민감한 데이터의 경우, Git에 포함되지 않도록 .env 파일을 사용하는 것이 좋습니다.
Compose 명령
서비스 빌드 및 실행
# Start all services
docker-compose up
# Start in detached mode (background)
docker-compose up -d
# Build or rebuild services
docker-compose build
# Build and start
docker-compose up --build
# Stop services
docker-compose down
# Stop and remove volumes
docker-compose down -v
로그 및 상태 보기
# View logs of all services
docker-compose logs
# Follow logs of a specific service
docker-compose logs -f web
# See running services
docker-compose ps
결론
Docker Compose는 내가 멀티‑컨테이너 애플리케이션을 개발하고 배포하는 방식을 근본적으로 바꾸어 놓았습니다. 수십 개의 명령과 세심한 조정이 필요했던 작업을 이제는 하나의 파일에 정의하고 한 번의 명령으로 실행할 수 있게 되었습니다.
핵심 이점:
- 프로덕션과 완벽히 일치하는 개발 환경
- 새로운 팀원을 위한 쉬운 온보딩
- 환경 전반에 걸친 일관된 배포
- 간소화된 로컬 개발 워크플로우
Docker를 사용하고 여러 컨테이너를 관리한다면, Compose는 반드시 툴킷에 포함시켜야 합니다.
다음 주제: “프로덕션에서의 Docker: 개발부터 배포까지”