demo / Dockerfile
tekville's picture
Initial commit
ff72db3
# Build Stage
FROM python:3.11-slim as builder
# μ‚¬μš©μž ν™˜κ²½ λ³€μˆ˜ μ„€μ •
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# μ‚¬μš©μž 생성 및 κΆŒν•œ μ„€μ •
RUN useradd -m -d $HOME -s /bin/bash user
# μž‘μ—… 디렉터리 μ„€μ •
WORKDIR $HOME/app
# μ‹œμŠ€ν…œ νŒ¨ν‚€μ§€ μ—…λ°μ΄νŠΈ 및 ν•„μˆ˜ νŒ¨ν‚€μ§€ μ„€μΉ˜
RUN apt-get update && apt-get install -y \
build-essential \
libmariadb-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Python νŒ¨ν‚€μ§€ 관리
RUN pip install --upgrade pip
# μ˜μ‘΄μ„± 파일 볡사
COPY --chown=user:user requirements.txt ./
# Python νŒ¨ν‚€μ§€ μ„€μΉ˜
RUN pip install --no-cache-dir -r requirements.txt
# Runtime Stage
FROM python:3.11-slim
# μ‚¬μš©μž ν™˜κ²½ λ³€μˆ˜ μ„€μ •
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# μ‚¬μš©μž 생성 및 κΆŒν•œ μ„€μ •
RUN useradd -m -d $HOME -s /bin/bash user
# μž‘μ—… 디렉터리 μ„€μ •
WORKDIR $HOME/app
# ν•„μš”ν•œ μ‹œμŠ€ν…œ νŒ¨ν‚€μ§€ μ„€μΉ˜
RUN apt-get update && apt-get install -y \
libmariadb-dev \
wget \
git \
&& rm -rf /var/lib/apt/lists/*
# Build Stageμ—μ„œ μ„€μΉ˜λœ Python νŒ¨ν‚€μ§€ 볡사
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ½”λ“œ 볡사
COPY --chown=user:user . .
# 포트 λ…ΈμΆœ (FastAPI κΈ°λ³Έ 포트: 8000)
EXPOSE 8000
# μ—…λ‘œλ“œ 디렉터리 생성 및 κΆŒν•œ μ„€μ •
RUN mkdir -p $HOME/app/uploaded_files && \
chown -R user:user $HOME/app/uploaded_files && \
chmod -R 777 $HOME/app/uploaded_files
# μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 싀행을 μ‚¬μš©μž κΆŒν•œμœΌλ‘œ μ‹€ν–‰
USER user
# FastAPI μ‹€ν–‰ λͺ…λ Ή
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]