Skip to content

Instantly share code, notes, and snippets.

@trvrm
Created July 15, 2020 20:32
Show Gist options
  • Save trvrm/360961be6301d141eb4e3b6f1bb3a6db to your computer and use it in GitHub Desktop.
Save trvrm/360961be6301d141eb4e3b6f1bb3a6db to your computer and use it in GitHub Desktop.
FROM python:3.6 as build
RUN pip install pipenv
WORKDIR /app
COPY Pipfile Pipfile.lock /app/
RUN PIPENV_VENV_IN_PROJECT=1 pipenv sync
FROM python:3.6-slim as application
COPY --from=build /app/.venv /app/.venv/
COPY ./myapp /app/myapp
EXPOSE 80
CMD ["/app/.venv/bin/uvicorn", "--port","80", "--host","0.0.0.0", "myapp:app"]
@trvrm
Copy link
Author

trvrm commented Jul 15, 2020

Skeleton for build Python apps in docker using multistage builds and Pipenv.

  • Produces reasonably small output images that don't have unnecessary build tools lying around as a potential security risk.
  • Allows complete dependency control via Pipenv
  • Has short build times when making code changes
  • Has longer build times when changes have been made Pipfile/Pipfile.lock
  • Requires running the same version of Python on your dev machine as in docker to create Pipfile.lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment