Created
January 10, 2023 21:31
-
-
Save eevmanu/255c631b85bef7f1c84a32c3dad7c09a to your computer and use it in GitHub Desktop.
random example of multi-stage build of a fastapi app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------------------------- | |
# temp stage | |
FROM python:3.10.9-slim-bullseye as builder | |
WORKDIR /code | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PYTHONUNBUFFERED 1 | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends gcc | |
RUN python -m venv /opt/venv | |
ENV PATH="/opt/venv/bin:$PATH" | |
COPY ./requirements.txt /code/requirements.txt | |
RUN pip install -r /code/requirements.txt | |
# -------------------------------------------------------------------------------- | |
# final stage | |
FROM python:3.10.9-slim-bullseye | |
COPY --from=builder /opt/venv /opt/venv | |
WORKDIR /code | |
ENV PATH="/opt/venv/bin:$PATH" | |
COPY ./app.py /code/app.py | |
ENTRYPOINT ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"] | |
# -------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment