← 가이드 목록으로 ← Back to guides

Docker 프로덕션 배포와 보안 완벽 가이드 Docker Production Deployment & Security Complete Guide

프로덕션 환경에서 Docker를 안전하게 운영하려면 이미지 보안, 런타임 보안, 네트워크 보안이 필수입니다. Trivy로 취약점을 스캔하고 Distroless 이미지로 공격 표면을 최소화하세요.

Running Docker safely in production requires image security, runtime security, and network security. Scan vulnerabilities with Trivy and minimize attack surface with Distroless images.

이미지 보안 스캐닝 Image Security Scanning

Trivy는 컨테이너 이미지의 취약점을 스캔하는 오픈소스 도구입니다. CI/CD 파이프라인에 통합하여 빌드 시점에 보안 문제를 발견하세요.

Trivy is an open-source tool for scanning container image vulnerabilities. Integrate into CI/CD pipelines to detect security issues at build time.

# Trivy 설치
$ brew install trivy

# 이미지 스캔
$ trivy image --severity HIGH,CRITICAL myapp:latest

# 결과를 JSON으로 출력
$ trivy image -f json -o results.json myapp:latest

# Dockerfile 검사 (설정 미스 감지)
$ trivy config --severity HIGH,CRITICAL .
# Install Trivy
$ brew install trivy

# Scan image
$ trivy image --severity HIGH,CRITICAL myapp:latest

# Output results as JSON
$ trivy image -f json -o results.json myapp:latest

# Check Dockerfile (detect misconfigs)
$ trivy config --severity HIGH,CRITICAL .

Distroless 이미지 Distroless Images

Distroless 이미지는 애플리케이션 실행에 필요한 최소한의 런타임만 포함합니다. 쉘, 패키지 매니저가 없어 공격 표면이 크게 줄어듭니다.

Distroless images contain only the minimal runtime needed to run applications. No shell or package manager significantly reduces attack surface.

# Distroless 멀티스테이지 빌드
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Distroless 런타임 이미지
FROM gcr.io/distroless/nodejs20-debian12
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["dist/main.js"]
# Distroless multi-stage build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Distroless runtime image
FROM gcr.io/distroless/nodejs20-debian12
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["dist/main.js"]

런타임 보안 설정 Runtime Security Settings

# 보안 강화 컨테이너 실행
$ docker run \
  --read-only \
  --cap-drop=ALL \
  --security-opt=no-new-privileges \
  --user 1000:1000 \
  --memory 512m \
  --cpus 0.5 \
  myapp:latest
# Run container with security hardening
$ docker run \
  --read-only \
  --cap-drop=ALL \
  --security-opt=no-new-privileges \
  --user 1000:1000 \
  --memory 512m \
  --cpus 0.5 \
  myapp:latest

🔒 보안 플래그 설명 🔒 Security Flags Explained

  • --read-only: 파일시스템 읽기 전용
  • --cap-drop=ALL: 모든 Linux capabilities 제거
  • --no-new-privileges: 권한 상승 방지
  • --user: non-root 사용자로 실행
  • --read-only: Read-only filesystem
  • --cap-drop=ALL: Drop all Linux capabilities
  • --no-new-privileges: Prevent privilege escalation
  • --user: Run as non-root user

⚠️ 프로덕션 체크리스트 ⚠️ Production Checklist

  • 이미지에 시크릿/환경변수 하드코딩 금지
  • latest 태그 대신 버전 고정
  • 이미지 서명 및 검증 (Cosign)
  • 정기적인 베이스 이미지 업데이트
  • Never hardcode secrets/env vars in images
  • Pin versions instead of latest tag
  • Sign and verify images (Cosign)
  • Regularly update base images

💡 이미지 크기 최적화 💡 Image Size Optimization

  • Alpine/Distroless 베이스 이미지 사용
  • .dockerignore로 불필요한 파일 제외
  • 레이어 수 최소화 (RUN 명령 합치기)
  • docker image history로 레이어 분석
  • Use Alpine/Distroless base images
  • Exclude unnecessary files with .dockerignore
  • Minimize layers (combine RUN commands)
  • Analyze layers with docker image history