Skip to content

Instantly share code, notes, and snippets.

@un-def
Last active December 23, 2021 09:31
Show Gist options
  • Save un-def/a45a0de4563c69f713cd9c3b2b03cc86 to your computer and use it in GitHub Desktop.
Save un-def/a45a0de4563c69f713cd9c3b2b03cc86 to your computer and use it in GitHub Desktop.
Python Docker multistage build template
ARG python_version
FROM python:${python_version}-alpine AS base
FROM base AS builder
COPY requirements.txt /tmp/
RUN pip install --target=/tmp/build --no-deps -r /tmp/requirements.txt
FROM base
ARG python_version
WORKDIR /opt/project/
COPY --from=builder /tmp/build/ /usr/local/lib/python${python_version}/site-packages/
COPY project/ project/
CMD ["python", "-m", "project"]
@un-def
Copy link
Author

un-def commented Dec 23, 2021

docker build --build-arg python_version=3.10 [...]

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