Created
March 22, 2025 19:42
-
-
Save jerheff/9d9e1ddec9ad9ac0a937309e4f31e0c9 to your computer and use it in GitHub Desktop.
Example Dockerfile using uv provided python
This file contains hidden or 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
# syntax = docker/dockerfile:1 | |
ARG BASE_IMAGE=public.ecr.aws/amazonlinux/amazonlinux:2023 | |
FROM ${BASE_IMAGE} AS builder | |
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | |
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy | |
ENV UV_PYTHON_INSTALL_DIR=/python UV_PYTHON_PREFERENCE=only-managed | |
# Install Python before the project for caching | |
RUN uv python install 3.12.9 | |
WORKDIR /app | |
RUN --mount=type=cache,target=/root/.cache/uv \ | |
--mount=type=bind,source=uv.lock,target=uv.lock \ | |
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | |
uv sync --frozen --no-install-project --no-dev | |
ADD . /app | |
RUN --mount=type=cache,target=/root/.cache/uv \ | |
uv sync --frozen --no-dev | |
FROM ${BASE_IMAGE} | |
COPY --from=builder --chown=python:python /python /python | |
COPY --from=builder --chown=app:app /app /app | |
ENV PATH="/app/.venv/bin:$PATH" | |
WORKDIR /app | |
CMD ["python", "app.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment