Skip to content

Instantly share code, notes, and snippets.

@jjo
Last active May 13, 2020 15:59
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 jjo/edfeb55ce3d393afc4b48311a43a3881 to your computer and use it in GitHub Desktop.
Save jjo/edfeb55ce3d393afc4b48311a43a3881 to your computer and use it in GitHub Desktop.
Generic python dockerfile for multistage builds
FROM python:3.8-slim as compile-image
RUN apt-get update && apt-get install -y --no-install-recommends build-essential gcc && apt-get clean
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
FROM python:3.8-slim as runtime-image
COPY --from=compile-image /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY . /app
## Replace my-app.py by yours :)
CMD ["/app/my-app.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment