Created
November 19, 2019 22:00
-
-
Save francbartoli/abb2a8a4376d23f230f4e40d291ac199 to your computer and use it in GitHub Desktop.
A multi-stage Dockerfile to build an image for a minimal python pipenv-managed app
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
FROM python:3.7 as build | |
# The python:3.7 image is HUGE but already comes with all the essentials | |
# for compiling (most) python modules with native dependencies | |
ENV LC_ALL C.UTF-8 | |
ENV LANG C.UTF-8 | |
RUN pip install pipenv | |
WORKDIR /build | |
COPY Pipfile Pipfile.lock /build/ | |
RUN bash -c 'PIPENV_VENV_IN_PROJECT=1 pipenv install' | |
FROM python:3.7-slim as application | |
# But python:3.7-slim is ~143MB, so you can expect your final image | |
# size to be 143 + dependencies + application. | |
# A scrapy+sqlalchemy+psycopg2 project ends up at ~225MB | |
WORKDIR /app | |
COPY --from=build /build /app/ | |
COPY . /app/ | |
# Change this to call your app | |
CMD .venv/bin/python -mMYAPPLICATION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment