Docker Caching Optimization
-
배경: fast api server에서 SBERT를 사용하고 있음. runtime에 SBERT를 import 하면 느린 문제가 있어서 Docker build에 pre-download를 추가 하면서 Docker build 시간이 느려지는 문제 발생
-
문제 분석: 자주 변경되는 application code를 copy한 이후에 SBERT 모델을 다운로드를 해서 캐싱이 안 되는 상황
-
해결: docker image의 layer cache 최적화를 위해, SBERT Model 다운로드를 진행한 후 application code를 copy하도록 변경
# Copy requirements first for better caching
COPY requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
- # Copy application code
- COPY . .
# Pre-download BGE-M3 model into the image so it's not fetched at runtime
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('BAAI/bge-m3')"
+ # Copy application code
+ COPY . .
- 결과: build 시간 19분을 단축
