File size: 1,772 Bytes
ff72db3 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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"]
|