Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ FROM nvidia/cuda:12.6.0-runtime-ubuntu24.04
WORKDIR /app

RUN apt-get update && \
apt-get install -y python3 python3-pip git && \
apt-get install -y python3 python3-venv python3-pip git && \
ln -s /usr/bin/python3 /usr/bin/python && \
pip install --upgrade pip && \
apt-get clean && rm -rf /var/lib/apt/lists/*
Comment on lines 5 to 8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

python3-venv를 추가하신 것은 좋은 결정입니다. 하지만 현재 Dockerfile에서는 가상 환경이 사용되지 않고 있어, 패키지들이 전역으로 설치되고 있습니다. 가상 환경을 사용하면 의존성을 격리하여 더 안정적이고 예측 가능한 환경을 구축할 수 있습니다.

또한, Docker 이미지 빌드 캐시를 더 효율적으로 사용하기 위해 requirements.txt 파일을 먼저 복사하여 의존성을 설치하고, 그 다음에 나머지 소스 코드를 복사하는 것이 좋습니다. 이렇게 하면 소스 코드만 변경되었을 때 매번 의존성을 다시 설치하는 것을 피할 수 있습니다.

이 두 가지 개선 사항을 적용하여 Dockerfile을 다음과 같이 리팩토링하는 것을 제안합니다:

FROM nvidia/cuda:12.6.0-runtime-ubuntu24.04

WORKDIR /app

# 시스템 의존성 설치
RUN apt-get update && \
    apt-get install -y python3 python3-venv python3-pip git && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# 가상 환경 생성 및 PATH 설정
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# 의존성 파일만 먼저 복사하여 설치 (Docker 캐시 최적화)
COPY app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 나머지 소스 코드 복사
COPY . .

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

이 리팩토링을 적용하면 ln -s /usr/bin/python3 /usr/bin/python 명령어는 더 이상 필요하지 않습니다. ENV PATH 설정을 통해 pythonpip 명령어는 자동으로 가상 환경 내의 버전을 사용하게 되기 때문입니다.


COPY . .
Expand Down
Loading