🌐
Astral
docs.astral.sh β€Ί uv β€Ί guides β€Ί integration β€Ί docker
Using uv in Docker | uv
1 week ago - See a complete example in the uv-docker-example project. Compiling Python source files to bytecode is typically desirable for production images as it tends to improve startup time (at the cost of increased installation time and image size). To enable bytecode compilation, use the --compile-bytecode flag: ... Alternatively, you can set the UV_COMPILE_BYTECODE environment variable to ensure that all commands within the Dockerfile ...
Discussions

Adding Python to Docker in 2 seconds using uv's Python command
Hmm this is interesting. I'm wondering if it's worth migrating from poetry to uv for our package management. We also use docker to containerize images for CI/docker compose local stacks. More on reddit.com
🌐 r/Python
45
160
September 7, 2024
Announcing uv: Python packaging in Rust
no fucking way now do a drop-in replacement for mypy as well, and my entire python toolkit will be handled by the same party pkg mgmt + lint + format + type checks More on reddit.com
🌐 r/Python
168
577
February 15, 2024
How do I manage a monorepo with multiple subprograms, each of which needs its own docker image?
At first I tried the uv package manager which has a workspace feature, but it is not possible to have separate docker images (as far as I've understand it) because you have one single lock file. There's nothing about having a single lockfile that prevents you from having mulitple dockerfiles. let's pretend we have this: monorepo β”œβ”€β”€ subproject1 β”‚ β”œβ”€β”€ file1.py β”‚ β”œβ”€β”€ file2.py β”‚ β”œβ”€β”€ Dockerfile β”‚ └── pyproject.toml β”œβ”€β”€ subproject2 β”‚ β”œβ”€β”€ file1.py β”‚ β”œβ”€β”€ file2.py β”‚ β”œβ”€β”€ Dockerfile β”‚ └── pyproject.toml └── pyproject.toml └── uv.lock You can still build each dockerfile with the uv.lock file, you just need to execute the dockerfiles from the context of monorepo eg docker build -t exampletag -f ./subproject<1|2>/Dockerfile .. now the dockerfile will have access to the monorepo's uv.lock file as well as all the contents of every subfolder. You will need to path everything in the dockerfile as if it was in the parent folder though. That's the only downside to this. Alternatively you can copy the uv.lock into the subfolders as part of some sort of pipeline job. Another option is to use build contexts . though depending on the docker pipeline this may add additional unwanted complexity if you don't wanna do multi-stage pipelines There may be some nuances I'm missing since I don't use uv or work on a monorepo with python but that should be the gist of it More on reddit.com
🌐 r/learnpython
7
5
November 5, 2024
uv with django and docker?
They have a guide on how to use uv with docker: Docker | uv (astral.sh) You can do a single build or multi-build. I use a multi-build and you don't have to actually install uv into docker like you do with the single build. Their demo is for fastapi but it's the same concept. More on reddit.com
🌐 r/django
17
11
September 18, 2024
🌐
GitHub
github.com β€Ί astral-sh β€Ί uv-docker-example
GitHub - astral-sh/uv-docker-example: An example of using uv in Docker images Β· GitHub
The run.sh script includes an example of invoking docker run for local development, mounting the source code for the project into the container so that edits are reflected immediately. The compose.yml file includes a Docker compose definition for the web application. It includes a watch directive for Docker compose, which is a best-practice method for updating the container on local changes. The Python application code for the project is at src/uv_docker_example/__init__.py β€” there's a command line entrypoint and a basic FastAPI application β€” both of which just display "hello world" output.
Starred by 762 users
Forked by 74 users
Languages Β  Dockerfile 81.4% | Shell 16.2% | Python 2.4%
🌐
Depot
depot.dev β€Ί docs β€Ί container-builds β€Ί how-to-guides β€Ί optimal-dockerfiles β€Ί python-uv-dockerfile
Optimal Dockerfile for Python with uv | Container Builds | Depot Documentation
# syntax=docker/dockerfile:1 FROM python:3.13-slim AS build COPY --from=ghcr.io/astral-sh/uv:0.8.21 /uv /uvx /bin/ WORKDIR /app ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy COPY uv.lock pyproject.toml ./ RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --no-install-project --no-dev COPY .
🌐
GitHub
github.com β€Ί astral-sh β€Ί uv-docker-example β€Ί blob β€Ί main β€Ί Dockerfile
uv-docker-example/Dockerfile at main Β· astral-sh/uv-docker-example
# Use a Python image with uv pre-installed Β· FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim Β· Β· # Setup a non-root user Β· RUN groupadd --system --gid 999 nonroot \ && useradd --system --gid 999 --uid 999 --create-home nonroot Β· Β· # Install the project into `/app` WORKDIR /app Β·
Author Β  astral-sh
🌐
Medium
medium.com β€Ί @shaliamekh β€Ί python-package-management-with-uv-for-dockerized-environments-f3d727795044
Python package management with uv for dockerized environments | by Raman Shaliamekh | Medium
December 3, 2024 - # docker/Dockerfile FROM python:3.13.0-slim ENV USER=uv-example-user \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_PROJECT_ENVIRONMENT=/usr/local RUN apt-get update && apt-get install --no-install-recommends -y \ curl \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && useradd -m -s /bin/bash $USER COPY --from=ghcr.io/astral-sh/uv:0.5.5 /uv /uvx /bin/ ENV APP_DIR=/home/$USER/src WORKDIR $APP_DIR RUN --mount=type=cache,target=/home/$USER/.cache/uv \ --mount=type=bind,source=src/uv.lock,target=uv.lock \ --mount=type=bind,source=src/pyproject.toml,target=pyproject.toml \ uv sync --frozen --no-install-project COPY src $APP_DIR RUN --mount=type=cache,target=/home/$USER/.cache/uv \ uv sync --frozen ENV PYTHONPATH=$APP_DIR RUN chown -R "$USER":"$USER" $APP_DIR USER $USER CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]
🌐
Hynek
hynek.me β€Ί articles β€Ί docker-uv
Production-ready Python Docker Containers with uv
September 24, 2024 - Anyways, if your application isn’t packaged for whatever reason: I have added inline notes how to adjust the Dockerfile. In a nutshell, instead of installing your application in the build step, you COPY it into the runtime container after COPYing /app over. Be careful to not overwrite /app. P.S. If you need more help with Docker, my friend Itamar Turner-Trauring has great resources for you. 2024-11-12: Added a workaround for #9046: Use absolute paths for UV_PYTHON on uv 0.5.0+.
🌐
Josh Kasuboski
joshkasuboski.com β€Ί posts β€Ί distroless-python-uv
Building a Python Docker Image with Distroless and Uv | Josh Kasuboski
March 8, 2025 - /app RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-dev --no-editable # Then, use a final image without uv FROM gcr.io/distroless/cc # Copy the Python version COPY --from=builder --chown=python:python /python /python WORKDIR /app # Copy the application from the builder COPY --from=builder --chown=app:app /app/.venv /app/.venv # 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", "run", "--host", "0.0.0.0", "/app/.venv/lib/python3.12/site-packages/uv_docker_example"]
Find elsewhere
🌐
Digon
digon.io β€Ί en β€Ί blog β€Ί 2025_07_28_python_docker_images_with_uv
Build Multistage Python Docker Images Using UV
July 27, 2025 - In this post, we walked through the process of building a minimal, reproducible and production-ready Docker image for a FastAPI application using uv and a multistage Dockerfile. We covered how to structure your Python project for efficient builds, how to manage dependencies with uv sync, and how to isolate the runtime environment for security and performance.
🌐
Mkennedy
mkennedy.codes β€Ί home β€Ί posts β€Ί docker images using uv's python
Docker images using uv's python β€’ Michael Kennedy's Thoughts on Technology
February 5, 2026 - For example, if most of our apps are based on Flask and use Granian, then we could add this line to the python-base image: RUN uv pip install --upgrade flask pydantic beanie RUN uv pip install --upgrade granian[pname] # No these packages should ...
🌐
Microsoft Developer Blogs
devblogs.microsoft.com β€Ί dev blogs β€Ί ise developer blog β€Ί dockerizing uv
Dockerizing UV - ISE Developer Blog
June 12, 2025 - We start with a specialized Python image (mcr.microsoft.com/cbl-mariner/base/python:3) that comes with UV pre-installed. Key environment variables (such as UV_COMPILE_BYTECODE and UV_LINK_MODE) are set to speed up dependency installations by enabling bytecode compilation and optimizing linking behavior. The working directory is set to /usr/app, and all project files are copied into this directory. A helper script (scripts/setup/Dockerfile/base.ba.sh) then installs the necessary build tools, ensuring that any dependencies requiring compilation are handled correctly.
🌐
PyDevTools
pydevtools.com β€Ί handbook β€Ί how-to β€Ί how-to-use-uv-in-a-dockerfile
How to use uv in a Dockerfile | pydevtools
3 weeks ago - For even smaller images, python:3.13-alpine is available, though Alpine’s musl libc can cause compatibility issues with some Python packages. Alternatively, let uv install Python itself by starting from a non-Python base image:
🌐
DEV Community
dev.to β€Ί kummerer94 β€Ί multi-stage-docker-builds-for-pyton-projects-using-uv-223g
Multi-Stage Docker Builds for Python Projects using uv - DEV Community
November 11, 2024 - A more general example for a Dockerfile ... be this: # syntax = docker/dockerfile:1.0-experimental # Base image FROM python:3.12 as build RUN apt-get update && apt-get install -y build-essential curl ENV VIRTUAL_ENV=/opt/venv \ PATH="/opt/venv/bin:$PATH" ADD https://astral.sh/uv/......
🌐
Docker Hub
hub.docker.com β€Ί r β€Ί astral β€Ί uv
astral/uv - Docker Image
The official Docker image for uv, the Python package manager.
🌐
Deanlofts
blog.deanlofts.xyz β€Ί guides β€Ί uv-python-docker
Mastering UV with Python and Docker: A Comprehensive Guide to Modern Python Development - Dean "Loftwah" Lofts
Here’s a complete example using FastAPI with custom UV integration. ... # syntax=docker/dockerfile:1.4 # Build stage FROM python:3.13-slim-bookworm AS builder # Install UV COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/ ENV UV_SYSTEM_PYTHON=1 WORKDIR /build # Copy dependency files COPY pyproject.toml uv.lock ./ # Install dependencies with caching RUN --mount=type=cache,target=/root/.cache/uv \ uv pip install --system --compile-bytecode \ --no-editable --only-binary :all: \ -r pyproject.toml # Final stage FROM python:3.13-slim-bookworm WORKDIR /app # Copy installed packages COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages # Copy application code COPY .
🌐
Medium
medium.com β€Ί @benitomartin β€Ί deep-dive-into-uv-dockerfiles-by-astral-image-size-performance-best-practices-5790974b9579
Deep Dive into uv Dockerfiles by Astral: Image Size, Performance & Best Practices | by Benito Martin | Medium
March 18, 2025 - FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy # Disable Python downloads, because we want to use the system interpreter # across both images. If using a managed Python version, it needs to be # copied from the build image into the final image; see `standalone.Dockerfile` # for an example.
🌐
YouTube
youtube.com β€Ί watch
How To Use uv in Production - Simple Docker Setup - YouTube
Today we learn how to use uv in production and how to deploy it with Docker.β—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—Ύβ—ΎπŸ“š Programming Books & Merch πŸ“šπŸ The Python Bible Book: https:/...
Published Β  June 6, 2025
🌐
r y x, r
ryxcommar.com β€Ί 2024 β€Ί 02 β€Ί 15 β€Ί how-to-cut-your-python-docker-builds-in-half-with-uv
How to cut your Python Docker build times in half with uv – r y x, r
March 4, 2024 - Long story short, the Python executable for the Python base image is located at /usr/local/bin/python. uv is insistent on users utilizing venvs, but you can bypass this by just defining your β€œvenv” to be where the global Python installation is inside the Docker image. uv recognizes the VIRTUAL_ENV env var internally. With uv version 0.1.12, this approach is no longer necessary due to the --system flag. This blog post is mostly a relic of the literal first few hours after uv came out. This post was originally written to provide an optimal Docker installation for uv 0.1.0, since it was not clear in 0.1.0 how to best install and use uv in a Dockerfile, and I was so excited for the project that I wanted to make sure everyone had access to it for their builds.
🌐
Hotovo
hotovo.com β€Ί blog β€Ί python-dockerfile-with-uv
Python Dockerfile with UV
August 19, 2025 - >FROM python:3.12-slim-bookworm AS builder >RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates >ADD https://astral.sh/uv/0.5.31/install.sh /uv-installer.sh >RUN sh /uv-installer.sh && rm /uv-installer.sh >ENV PATH="/root/.local/bin/:$PATH" >ENV UV_COMPILE_BYTECODE=1 >ENV UV_LINK_MODE=copy >WORKDIR /app >COPY pyproject.toml uv.lock ./ >RUN uv sync --frozen --no-install-project ># Run arbitrary Python with UV >RUN uv run python -c "import logging; logging.basicConfig(level=logging.INFO); logging.info('Hello, world')" >FROM python:3.12-slim-bookworm AS runtime >WORKDIR /app ># Copy the environment that UV created in the builder stage >COPY --from=builder /app/.venv /app/.venv >ENV PATH="/app/.venv/bin:$PATH" >ENV PYTHONPATH="/app/src:${PYTHONPATH}" >