GitHub
github.com › astral-sh › uv-docker-example
GitHub - astral-sh/uv-docker-example: An example of using uv in Docker images · GitHub
An example project for using uv in Docker images, with a focus on best practices for developing with the project mounted in the local image.
Starred by 762 users
Forked by 74 users
Languages Dockerfile 81.4% | Shell 16.2% | Python 2.4%
Astral
docs.astral.sh › uv › guides › integration › docker
Using uv in Docker | uv
2 weeks ago - uv provides both distroless Docker images, which are useful for copying uv binaries into your own image builds, and images derived from popular base images, which are useful for using uv in a container. The distroless images do not contain anything but the uv binaries. In contrast, the derived images include an operating system with uv pre-installed. As an example, to run uv in a container using a Debian-based image:
Best practices for using Python & uv inside Docker
You’re skipping past the first solution they offer, which is the more efficient distroless solution. You can literally just copy the standalone uv binary directly into your image; you don’t need to base your entire image on theirs. COPY --from=ghcr.io/astral-sh/uv:0.9.2 /uv /bin/ This takes ~43MiB, not the 77MiB you cite. More on reddit.com
Docker + uv - virtual environments
you can also just RUN pip install uv in the docker image to make things a bit simpler too. More on reddit.com
PSA: If you're starting a new project, try astral/uv!
At this point there's little reason not to use uv. More on reddit.com
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
Videos
17:14
Easy Python Package Management with UV Inside Docker | A FastAPI ...
10:49
How To Use uv in Production - Simple Docker Setup - YouTube
11:03
uv - Docker setup with a FastAPI application! | Using uv in ...
01:31
Does UV make Docker Containers Easy? #python #programming #coding ...
22:17
Docker Tutorial For Beginners - How To Containerize Python ...
18:47
This Is How You Write an Efficient Python Dockerfile - YouTube
GitHub
github.com › astral-sh › uv-docker-example › blob › main › Dockerfile
uv-docker-example/Dockerfile at main · astral-sh/uv-docker-example
An example of using uv in Docker images. Contribute to astral-sh/uv-docker-example development by creating an account on GitHub.
Author astral-sh
Hynek
hynek.me › articles › docker-uv
Production-ready Python Docker Containers with uv
September 24, 2024 - In case you wonder why I use virtual environments inside of Docker, I wrote it up for you. This workflow used to be tricky before uv 0.4.4 (readers of previous versions of this article will remember), but then it introduced the UV_PROJECT_ENVIRONMENT environment variable and made it a supported workflow.
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/compose.yaml --- services: uv-example: container_name: uv-example build: context: ../ dockerfile: docker/Dockerfile volumes: - ../src:/home/uv-example-user/src ports: - 8010:8000 healthcheck: test: ["CMD", "curl", "-f", "localhost:8000/healthcheck"] interval: 30s timeout: 5s retries: 5
GitHub
github.com › astral-sh › uv-docker-example › blob › main › multistage.Dockerfile
uv-docker-example/multistage.Dockerfile at main · astral-sh/uv-docker-example
An example of using uv in Docker images. Contribute to astral-sh/uv-docker-example development by creating an account on GitHub.
Author astral-sh
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.
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"]
Docker Hub
hub.docker.com › r › astral › uv
astral/uv - Docker Image
See the available images documentation for a description of uv's Docker image tagging scheme.
Reddit
reddit.com › r/python › best practices for using python & uv inside docker
r/Python on Reddit: Best practices for using Python & uv inside Docker
October 11, 2025 -
Getting uv right inside Docker is a bit tricky and even their official recommendations are not optimal.
It is better to use a two-step build process to eliminate uv from the final image size.
A two-step build process not only saves disk space but also reduces attack surface against security vulerabilities
Top answer 1 of 5
174
You’re skipping past the first solution they offer, which is the more efficient distroless solution. You can literally just copy the standalone uv binary directly into your image; you don’t need to base your entire image on theirs. COPY --from=ghcr.io/astral-sh/uv:0.9.2 /uv /bin/ This takes ~43MiB, not the 77MiB you cite.
2 of 5
52
The linked security issue is a bad example. If an attacker can use uv in your container, they could also download and run whatever executable they want and do not need to exploit bugs in uv for that. With very few exceptions, CVEs in unused executables in containers are almost never an issue, because if the attacker already has shell access to be able to use them, they won't gain anything from exploiting those bugs.
GitHub
github.com › astral-sh › uv-docker-example › blob › main › compose.yml
uv-docker-example/compose.yml at main · astral-sh/uv-docker-example
An example of using uv in Docker images. Contribute to astral-sh/uv-docker-example development by creating an account on GitHub.
Author astral-sh
Microsoft Developer Blogs
devblogs.microsoft.com › dev blogs › ise developer blog › dockerizing uv
Dockerizing UV - ISE Developer Blog
June 12, 2025 - This ensures that if only your application code changes while dependencies remain the same, Docker can cache the layer where dependencies were installed, leading to faster rebuilds. Use uv venv for Isolation: In the build stage, consider installing dependencies into a virtualenv path. For example, set an env variable ENV VIRTUAL_ENV=/opt/venv and do uv venv $VIRTUAL_ENV then uv pip install -r requirements.txt.
GitHub
github.com › astral-sh › uv-docker-example › activity
Activity · astral-sh/uv-docker-example
An example of using uv in Docker images. Contribute to astral-sh/uv-docker-example development by creating an account on GitHub.
Author astral-sh
GitHub
github.com › astral-sh › uv › blob › main › docs › guides › integration › docker.md
uv/docs/guides/integration/docker.md at main · astral-sh/uv
COPY --from=ghcr.io/astral-sh/uv:0.11.7 /uv /uvx /bin/ ... While the Dockerfile example above pins to a specific tag, it's also possible to pin a specific SHA256. Pinning a specific SHA256 is considered best practice in environments that require ...
Author astral-sh
Uvicorn
uvicorn.dev › deployment › docker
Docker - Uvicorn
docker build -t my-app . docker run -p 8000:8000 my-app · For more information on using uv with Docker, refer to the official uv Docker integration guide.