-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (38 loc) · 1.97 KB
/
Dockerfile
File metadata and controls
54 lines (38 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# --- 스테이지 1: 빌더 스테이지 (의존성 설치) ---
FROM python:3.10-slim-bullseye AS builder
WORKDIR /usr/src/app
# 시스템 의존성 설치
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc libmariadb-dev pkg-config && rm -rf /var/lib/apt/lists/*
# requirements.txt를 먼저 복사하여 Docker 캐시를 활용합니다.
COPY requirements.txt .
# pip 업그레이드
RUN python -m pip install --upgrade pip
# Python 의존성 설치
RUN pip install --no-cache-dir -r requirements.txt
# PyTorch CPU 버전 설치
RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
# --- 스테이지 2: 최종 이미지 스테이지 (실행 환경) ---
FROM python:3.10-slim-bullseye
WORKDIR /app
# 보안을 위해 non-root 사용자 생성
RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
# 빌더 스테이지에서 설치한 Python 패키지 및 실행 파일 복사
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# 애플리케이션 및 Alembic 관련 소스 코드 복사
COPY ./app ./app
COPY ./db ./db
COPY ./alembic.ini .
COPY ./alembic ./alembic
COPY ./logging.ini .
# 파일 소유권을 non-root 사용자로 변경
RUN chown -R appuser:appgroup /app
# non-root 사용자로 전환
USER appuser
# Uvicorn 서버가 리스닝할 포트 노출
EXPOSE 8001
# 컨테이너 시작 시 실행될 기본 명령어
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001", "--log-config", "logging.ini"]
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001", "--log-config", "logging.ini", "--proxy-headers", "--forwarded-allow-ips", "*"]
CMD ["uvicorn", "app.main:app","--host", "0.0.0.0","--port", "8001","--workers", "4","--limit-concurrency", "2500","--log-config", "logging.ini","--proxy-headers","--forwarded-allow-ips","*"]