-
-
Save tuananh/bf7070f8e202d1a74ac95e511eb25bcb to your computer and use it in GitHub Desktop.
An example Python web application distroless image using uv. An extremely fast Python package and project manager, written in Rust.
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
# Stage 0 | |
# Installs dependencies and builds the application | |
# Artifacts will be copied to the final image | |
FROM debian:12-slim AS build | |
ARG PYTHON_VERSION="3.13" | |
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin | |
ENV UV_COMPILE_BYTECODE="1" | |
ENV UV_LINK_MODE="copy" | |
ENV UV_PYTHON_INSTALL_DIR="/python" | |
ENV UV_PYTHON_PREFERENCE="only-managed" | |
WORKDIR /app | |
RUN uv python install $PYTHON_VERSION --no-cache | |
RUN --mount=type=bind,source=uv.lock,target=uv.lock \ | |
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | |
uv sync --frozen --no-cache --no-dev --no-editable | |
COPY src /app/src | |
# Stage 1 | |
# Uses GoogleContainerTools/distroless as a minimal base | |
# Contains only necessary files and build artifacts | |
# Caching improves build speed | |
FROM gcr.io/distroless/cc-debian12:nonroot | |
COPY --from=build /python /python | |
COPY --from=build /app /app | |
ENV PATH="/app/.venv/bin:$PATH" | |
WORKDIR /app | |
ENTRYPOINT ["uvicorn", "src.main:app"] | |
CMD ["--host=0.0.0.0", "--port=8000"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment