FROM python:3.10.9 # Set working directory early for clean pathing WORKDIR /code # Copy requirements and install them as root (good practice) COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # Hugging Face 캐시 디렉토리 설정 및 생성 (HF_HOME 고려) ENV TRANSFORMERS_CACHE=/tmp/huggingface_cache ENV HF_HOME=/tmp/huggingface_home RUN mkdir -p /tmp/huggingface_cache /tmp/huggingface_home # Matplotlib 캐시 디렉토리 설정 및 생성 ENV MPLCONFIGDIR=/tmp/matplotlib_cache RUN mkdir -p /tmp/matplotlib_cache # OpenGL 라이브러리 설치 (opencv-python 설치 전에) RUN apt-get update && apt-get install -y libgl1 # 사용자 생성 (UID 1000은 일반적인 비-root 사용자 ID) RUN adduser --uid 1000 user # !!! IMPORTANT: Change ownership of cache directories as root BEFORE switching user !!! RUN chown -R user:user /tmp/huggingface_cache /tmp/huggingface_home /tmp/matplotlib_cache # Switch to the non-root user for subsequent commands and application runtime USER user # Copy application code after switching user if you want it owned by 'user' # Or copy it before and then chown it. This approach is usually cleaner. # $HOME will now resolve to /home/user inside the container COPY --chown=user . /home/user/app WORKDIR /home/user/app CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]