Skip to content

Instantly share code, notes, and snippets.

@eevmanu
Created January 10, 2023 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eevmanu/255c631b85bef7f1c84a32c3dad7c09a to your computer and use it in GitHub Desktop.
Save eevmanu/255c631b85bef7f1c84a32c3dad7c09a to your computer and use it in GitHub Desktop.
random example of multi-stage build of a fastapi app
# --------------------------------------------------------------------------------
# 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