-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# An example using multi-stage image builds to create a final image without uv. | ||
|
||
# First, build the application in the `/app` directory. | ||
# See `Dockerfile` for details. | ||
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder | ||
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 | ||
ADD . /app | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
uv sync --frozen | ||
|
||
|
||
# Then, use a final image without uv | ||
FROM python:3.12-slim-bookworm | ||
# It is important to use the image that matches the builder, as the path to the | ||
# Python executable must be the same, e.g., using `python:3.11-slim-bookworm` | ||
# will fail. | ||
|
||
# Copy the application from the builder | ||
COPY --from=builder --chown=app:app /app /app | ||
|
||
# Place executables in the environment at the front of the path | ||
ENV PATH="/app/.venv/bin:$PATH" | ||
|
||
# Run the FastAPI application by default | ||
CMD ["fastapi", "dev", "--host", "0.0.0.0", "/app/src/uv_docker_example"] |
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