Skip to content

Instantly share code, notes, and snippets.

@arischow
Last active September 7, 2020 17:22
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 arischow/5d709661adfba9301fcd9597b573231d to your computer and use it in GitHub Desktop.
Save arischow/5d709661adfba9301fcd9597b573231d to your computer and use it in GitHub Desktop.
Dockerfile multi-stage build for Python
# build wheels
FROM python:3.7.9-buster as builder
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
# pip:
PIP_NO_CACHE_DIR=yes \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100
RUN mkdir /svc
WORKDIR /svc
ADD ./requirements.txt .
RUN pip install wheel && pip wheel -r requirements.txt --wheel-dir=/svc/wheels
# clean slate
FROM python:3.7.9-slim-buster as production
# python packages
COPY --from=builder /svc /svc
WORKDIR /svc
RUN pip install --no-index --find-links=/svc/wheels -r requirements.txt && \
rm -rf /svc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment