Created
March 26, 2024 13:01
-
-
Save MtkN1/e07bf32865c64fecc4e5f1f0c8e4949c to your computer and use it in GitHub Desktop.
Dockerfile for uv
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
# build stage | |
FROM python:3.12-bookworm AS build | |
RUN curl -LsSf https://astral.sh/uv/install.sh | sh | |
ENV PATH="/root/.cargo/bin:$PATH" | |
WORKDIR /app | |
COPY requirements.txt requirements.txt | |
RUN uv venv \ | |
&& uv pip sync --no-cache requirements.txt | |
# runtime stage | |
FROM python:3.12-slim-bookworm AS runtime | |
WORKDIR /app | |
COPY --from=build /app/.venv /app/.venv | |
ENV PATH="/app/.venv/bin:$PATH" \ | |
VIRTUAL_ENV="/app/.venv" | |
COPY main.py /app | |
CMD [ "python", "-Bu", "main.py" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a minimal sample of a Python container App using
uv
.Thanks to
uv
, dependency installation and container building become extremely fast.Workflows
uv venv
pyproject.toml
uv pip compile -o requirements.txt pyproject.toml
uv pip compile --extra dev -o requirements-dev.txt pyproject.toml
uv sync requirements-dev.txt
main.py
docker build -t myapp .
Minimal
pyproject.toml