Astral
docs.astral.sh › uv › guides › integration › docker
Using uv in Docker - Astral Docs
4 days ago - Alternatively, the UV_PROJECT_ENVIRONMENT setting can be set before syncing to install to the system Python environment and skip environment activation entirely. To use installed tools, ensure the tool bin directory is on the path: ... $ docker run -it $(docker build -q .) /bin/bash -c "cowsay -t hello" _____ | hello | ===== \ \ ^__^ (oo)\_______ (__)\ )\/\ ||----w | || ||
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 794 users
Forked by 77 users
Languages Dockerfile 82.8% | Shell 15.0% | Python 2.2%
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
dockerfile - Docker: fail to resolve: RUN uv sync --frozen --no-cache - Stack Overflow
Explore Stack Internal ... So, for context: I am trying to start working on a FastApi proj using UV framework, which is great. I am using Python and a Windows computer. Now, the app is still straightforward and runs well on local. When trying to build the image using Docker, however, an error pops up, saying: => ERROR [stage-0 5/5] RUN uv sync --frozen --no-cache 0.4s [stage-0 5/5] RUN uv sync --frozen --no-cache: 0.330 /bin/sh: 1: uv: not found Dockerfile... More on stackoverflow.com
How to use UV workspaces on a docker container - Stack Overflow
Following the doc on how to use uv with docker, I have the following Dockerfile FROM nvidia/cuda:12.6.1-base-ubuntu24.04 COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /app ENV More on stackoverflow.com
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
How do I install from a private PyPI index in a uv Dockerfile?
Use Docker's `--mount=type=secret` flag to expose the index URL only during a `RUN` step, then read it into `UV_EXTRA_INDEX_URL` for the duration of the command. Using `ARG` or `ENV` for credentials would bake them into the image history; the secret mount keeps them out of every layer.
pydevtools.com
pydevtools.com › handbook › how-to › how-to-use-uv-in-a-dockerfile
How to use uv in a Dockerfile | pydevtools
Why split uv sync into two stages in a Dockerfile?
Running `uv sync --frozen --no-install-project` before copying the source code, then `uv sync --frozen` after, lets Docker cache the dependency layer separately from the project source. When only application code changes, Docker reuses the cached dependency layer and skips reinstalling packages, which makes most rebuilds much faster.
pydevtools.com
pydevtools.com › handbook › how-to › how-to-use-uv-in-a-dockerfile
How to use uv in a Dockerfile | pydevtools
How do I install uv inside a Docker image?
Copy the uv binary from the official image with `COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/`. This avoids running the install script and keeps the image layer small. Pin the tag (for example `ghcr.io/astral-sh/uv:0.10.9`) for reproducible builds.
pydevtools.com
pydevtools.com › handbook › how-to › how-to-use-uv-in-a-dockerfile
How to use uv in a Dockerfile | pydevtools
Videos
GitHub
github.com › astral-sh › uv-docker-example › blob › main › Dockerfile
uv-docker-example/Dockerfile at main · astral-sh/uv-docker-example
# Installing separately from its dependencies allows optimal layer caching · COPY . /app · RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --locked · · # Place executables in the environment at the front of the path · ENV PATH="/app/.venv/bin:$PATH" ·
Author astral-sh
Depot
depot.dev › docs › container-builds › optimal-dockerfiles › python-uv-dockerfile
Optimal Dockerfile for Python with uv | Container Builds | Depot Documentation
USER appuser ENTRYPOINT ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]Copy code · The runtime stage uses a clean slim image and creates a non-root user for security. We copy the entire application including the virtual environment from the build stage and set proper ownership. Cache mounts in this Dockerfile speed up builds by persisting the package manager cache.
PyDevTools
pydevtools.com › handbook › how-to › how-to-use-uv-in-a-dockerfile
How to use uv in a Dockerfile | pydevtools
2 weeks ago - RUN --mount=type=cache,target=/root/.cache/uv \ uv sync --frozen --no-install-project · When using cache mounts, set UV_LINK_MODE=copy to suppress warnings about cross-filesystem linking (uv falls back to copying automatically, but the warning is noisy): ... Add this alongside the other environment variables in your Dockerfile.
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 - To initialize the project, let’s start with a minimal Dockerfile. # 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 COPY src $APP_DIR ENV PYTHONPATH=$APP_DIR RUN chown -R "$USER":"$USER" $APP_DIR USER $USER CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]
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.
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+.
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 - Before we dive into pros, cons, and differences, let’s quickly describe each Dockerfile. An example of using a single stage with uv pre-installed. # Use a Python image with uv pre-installed FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim # Install the project into `/app` WORKDIR /app # Enable bytecode compilation ENV UV_COMPILE_BYTECODE=1 # Copy from the cache instead of linking since it's a mounted volume ENV UV_LINK_MODE=copy # Install the project's dependencies using the lockfile and settings 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 # Then, add the rest of the project source code and install it ADD .
Vincent-roger
website.vincent-roger.fr › blog › 2025 › 10-02-efficient-dockerfile-with-uv
Efficient Docker Builds with uv - Vincent ROGER, (PhD)
October 2, 2025 - See the official docs here for ... . RUN uv sync --no-dev --frozen # Copy rest of the project ADD main.py /workspace # Default entry point CMD uv run python main.py...
Rho Signal
rhosignal.com › posts › uv-in-docker
Fast python package installs with uv in Docker | Rho Signal
December 22, 2024 - Here’s the dockerfile that I use to install packages with uv in Docker. Ensure that you pin your version of uv as breaking changes do occur! ... When you run python inside the container you should not need to active the virtual environment because we have added the virtual environment to the PATH.
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 - A Dockerfile for python-base might look like this: FROM linuxbase:latest # our customized Ubuntu ENV PATH=/venv/bin:$PATH ENV PATH=/root/.cargo/bin:$PATH # install uv RUN curl -LsSf https://astral.sh/uv/install.sh | sh # set up a virtual env to use for whatever app is destined for this container.
GitHub
github.com › shaunhegarty › uv-docker-examples
GitHub - shaunhegarty/uv-docker-examples: Some single and multi stage Dockerfile examples using uv · GitHub
uv run effectively runs uv sync before each, meaning we always need to include --no-dev in any case where uv run is used or we'll end up installing the packages in each container or syncing the environment each time uv run is called.
Author shaunhegarty
Digon
digon.io › en › blog › 2025_07_28_python_docker_images_with_uv
Build Multistage Python Docker Images Using UV
July 27, 2025 - The pyproject.toml file is central ... pip and uv. In the project table we can see the project’s name, version, description, and dependencies. With the project initialized, we need to create a few additional files to structure our application and Docker build process. These include the Dockerfile for the multistage build, the main FastAPI application file (main.py), and an entrypoint file (__main__.py) for running the ...
Docker Hub
hub.docker.com › r › astral › uv
astral/uv - Docker Image
The official Docker image for uv, the Python package manager.
LiteLLM
aidoczh.com › uv › guides › integration › docker › index.html
Using uv in Docker | uv
May 19, 2025 - Dockerfile · ENV PATH=/root/.local/bin:$PATH RUN uv tool install cowsay · $ docker run -it $(docker build -q .) /bin/bash -c "cowsay -t hello" _____ | hello | ===== \ \ ^__^ (oo)\_______ (__)\ )\/\ ||----w | || || 注意 · 工具bin目录的位置可以通过在容器中运行uv tool dir --bin命令来确定。 ·
Stack Overflow
stackoverflow.com › questions › 79785540 › how-to-use-uv-workspaces-on-a-docker-container
How to use UV workspaces on a docker container - Stack Overflow
Explore Stack Internal ... FROM nvidia/cuda:12.6.1-base-ubuntu24.04 COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /app ENV UV_LINK_MODE=copy 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 --locked --no-install-project --no-install-workspace