Skip to content

Instantly share code, notes, and snippets.

@francbartoli
Forked from caio/Dockerfile
Created Nov 19, 2019
Embed
What would you like to do?
A multi-stage Dockerfile to build an image for a minimal python pipenv-managed app
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