Last active
September 7, 2020 17:22
-
-
Save arischow/5d709661adfba9301fcd9597b573231d to your computer and use it in GitHub Desktop.
Dockerfile multi-stage build for Python
This file contains 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
# 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