Installing uv globally without pip

This is how you can install uv directly (without pip) into a Docker container:

FROM bitnami/deepspeed:0.14.0

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Copy your folder's files into the container.
COPY . /app

# go into the container
WORKDIR /app

# activate a virtual environment
RUN uv venv

# install into the virtual environment all dependencies
RUN uv pip install -r requirements.txt

# entry point - fun the shell to inspect your container
CMD ["sh"]

build by

docker build -t fastapi-app .
docker run --platform linux/amd64 -it fastapi-app # I am on a arm64 macos
 16:28:00.95 INFO  ==> 
 16:28:00.96 INFO  ==> Welcome to the Bitnami deepspeed container
 16:28:00.98 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
 16:28:00.99 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
 16:28:01.00 INFO  ==> Upgrade to Tanzu Application Catalog for production environments to access custom-configured and pre-packaged software components. Gain enhanced features, including Software Bill of Materials (SBOM), CVE scan result reports, and VEX documents. To learn more, visit https://bitnami.com/enterprise
 16:28:01.01 INFO  ==> 
 16:28:01.04 INFO  ==> Configuring libnss_wrapper
$ which uv
/usr/bin/uv
$ ls -hals /usr/bin/uv
31M -rwxr-xr-x 1 0 deepspeed 31M Mar 26 00:57 /usr/bin/uv

So you are running uv as deepspeed.

Installing uv with pip

This Dockerfile in which you use pip to install uv first, works, too. Here - as others pointed out, too - you have to make uv visible by adding ~/.local/bin to your PATH variable.

Another issue is that the user deepspeed runs into permission problems when installing the pip packages. Like in the solution given without pip, too. The trick is to activate first a uv environment by uv venv. By that, now, all the requirements.txt packages will be installed locally. And thus, you don't have any permission issues.

FROM bitnami/deepspeed:0.14.0

# Copy the application into the container.
COPY . /app

WORKDIR /app

RUN pip install uv

ENV PATH=/.local/bin:$PATH

RUN uv venv  # activates uv virtual environment - avoids permission issues
RUN uv pip install -r requirements.txt # now, installation is flawless


# entry point (to inspect the container)
CMD ["sh"]

Without RUN uv venv, or when trying to install with RUN uv pip install --system -r requirements.txt, you run into permission errors:

2.499 error: failed to remove file `/opt/bitnami/python/lib/python3.10/site-packages/Jinja2-3.1.3.dist-info/INSTALLER`: Permission denied (os error 13)

build by

docker build -t fastapi-app .
docker run --platform linux/amd64 -it fastapi-app # I am on a arm64 macos

This shell however behaves very weirdly.

  1. It doesn't recognize uv. Only after export PATH=/.local/bin:$PATH it can recognize uv.
  2. It was not possible to reactivate the uv virtual environment into which fastapi was installed into. fastapi as well as dotenv etc are present in /app/.venv/bin/. However, $ cd /app and $ uv venv just overwrites /app/.venv and creates a new virtual environment. When starting directly $ python, then import fastapi didn't work.
  3. Only $ uv run python run a Python console which runs import fastapi. So $ uv run python is the solution.

Does someone know how to activate the original virtual environment? /app/.venv/bin/activate didn't work source was not found when doing source /app/.venv/bin/activate.

Even the PYTHONPATH manipulating didn't work.

I recommend the first solution therefore.

Answer from Gwang-Jin Kim on Stack Overflow
🌐
Astral
docs.astral.sh › uv › guides › integration › docker
Using uv in Docker | uv
2 weeks ago - The --system flag can be used to ... a virtual environment, the --system flag should be omitted from uv invocations: ... COPY requirements.txt . RUN uv pip install -r requirements.txt...
🌐
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 - You can verify this by running ... with the necessary folders and files. mkdir uv-docker-example && cd uv-docker-example \ && mkdir docker src && touch docker/Dockerfile docker/compose.yaml...
🌐
Microsoft Developer Blogs
devblogs.microsoft.com › dev blogs › ise developer blog › dockerizing uv
Dockerizing UV - ISE Developer Blog
June 12, 2025 - RUN uv venv /opt/venv && uv pip install -r requirements.txt # OR RUN uv pip install --system · Losing UV’s speed benefits due to Docker layer caching: Docker caches image layers, but each RUN command is a new layer.
🌐
Hynek
hynek.me › articles › docker-uv
Production-ready Python Docker Containers with uv
September 24, 2024 - 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 ...
🌐
Reddit
reddit.com › r/learnpython › installing dependencies with `uv sync` system-wide in a docker image
r/learnpython on Reddit: Installing dependencies with `uv sync` system-wide in a Docker image
January 6, 2025 -

EDIT: See my solution in the comments!

I've loved uv's local DevEx until now, but I can't seem to find the "recommended"/"best" way to create a docker image that installs all my dependencies system-wide (without a venv) in a Docker image.

I've tried with a 'pyproject.toml' (and associated 'uv.lock'):

[project]
name = "api"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "fastapi>=0.115.6", 
    etc...
]

[dependency-groups]
dev = [
    "pytest>=8.3.4",
    etc...
]

And a Dockerfile:

FROM ghcr.io/astral-sh/uv:python3.13-alpine

#ENV UV_PROJECT_ENVIRONMENT="/usr/local/bin/" TODO ???
ENV PYTHONUNBUFFERED True

WORKDIR /app
COPY . .
RUN uv sync --locked --python-preference system --no-dev

BUT exec'ing into the image after build, I see no '.venv/' and:

/app # python main.py 
Traceback (most recent call last):
  File "/app/main.py", line 1, in <module>
    from fastapi import FastAPI
ModuleNotFoundError: No module named 'fastapi'
  • Should I be using uv install --system... instead or is that deprecated?

  • Should I use UV_PROJECT_ENVIRONMENT?

  • Should I simply run everything within a venv inside containers somehow?

Any help or suggestions is greatly appreciated!!

Top answer
1 of 3
1

Installing uv globally without pip

This is how you can install uv directly (without pip) into a Docker container:

FROM bitnami/deepspeed:0.14.0

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Copy your folder's files into the container.
COPY . /app

# go into the container
WORKDIR /app

# activate a virtual environment
RUN uv venv

# install into the virtual environment all dependencies
RUN uv pip install -r requirements.txt

# entry point - fun the shell to inspect your container
CMD ["sh"]

build by

docker build -t fastapi-app .
docker run --platform linux/amd64 -it fastapi-app # I am on a arm64 macos
 16:28:00.95 INFO  ==> 
 16:28:00.96 INFO  ==> Welcome to the Bitnami deepspeed container
 16:28:00.98 INFO  ==> Subscribe to project updates by watching https://github.com/bitnami/containers
 16:28:00.99 INFO  ==> Submit issues and feature requests at https://github.com/bitnami/containers/issues
 16:28:01.00 INFO  ==> Upgrade to Tanzu Application Catalog for production environments to access custom-configured and pre-packaged software components. Gain enhanced features, including Software Bill of Materials (SBOM), CVE scan result reports, and VEX documents. To learn more, visit https://bitnami.com/enterprise
 16:28:01.01 INFO  ==> 
 16:28:01.04 INFO  ==> Configuring libnss_wrapper
$ which uv
/usr/bin/uv
$ ls -hals /usr/bin/uv
31M -rwxr-xr-x 1 0 deepspeed 31M Mar 26 00:57 /usr/bin/uv

So you are running uv as deepspeed.

Installing uv with pip

This Dockerfile in which you use pip to install uv first, works, too. Here - as others pointed out, too - you have to make uv visible by adding ~/.local/bin to your PATH variable.

Another issue is that the user deepspeed runs into permission problems when installing the pip packages. Like in the solution given without pip, too. The trick is to activate first a uv environment by uv venv. By that, now, all the requirements.txt packages will be installed locally. And thus, you don't have any permission issues.

FROM bitnami/deepspeed:0.14.0

# Copy the application into the container.
COPY . /app

WORKDIR /app

RUN pip install uv

ENV PATH=/.local/bin:$PATH

RUN uv venv  # activates uv virtual environment - avoids permission issues
RUN uv pip install -r requirements.txt # now, installation is flawless


# entry point (to inspect the container)
CMD ["sh"]

Without RUN uv venv, or when trying to install with RUN uv pip install --system -r requirements.txt, you run into permission errors:

2.499 error: failed to remove file `/opt/bitnami/python/lib/python3.10/site-packages/Jinja2-3.1.3.dist-info/INSTALLER`: Permission denied (os error 13)

build by

docker build -t fastapi-app .
docker run --platform linux/amd64 -it fastapi-app # I am on a arm64 macos

This shell however behaves very weirdly.

  1. It doesn't recognize uv. Only after export PATH=/.local/bin:$PATH it can recognize uv.
  2. It was not possible to reactivate the uv virtual environment into which fastapi was installed into. fastapi as well as dotenv etc are present in /app/.venv/bin/. However, $ cd /app and $ uv venv just overwrites /app/.venv and creates a new virtual environment. When starting directly $ python, then import fastapi didn't work.
  3. Only $ uv run python run a Python console which runs import fastapi. So $ uv run python is the solution.

Does someone know how to activate the original virtual environment? /app/.venv/bin/activate didn't work source was not found when doing source /app/.venv/bin/activate.

Even the PYTHONPATH manipulating didn't work.

I recommend the first solution therefore.

2 of 3
0

The installed uv binary is not on PATH, and presumably since it's not a regular Python wrapper script, pip doesn't print out the helpful warning about that.

Refer to the .local-installed uv manually:

RUN pip install uv && ~/.local/bin/uv pip install --system --no-cache -r requirements.txt

Note that --system will likely fail since that image is clearly not running these commands as root.

(Personally, I would probably not use a bitnami/deepspeed image.)

🌐
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 - Here’s a TLDR of how to use it in Docker, assuming you are using the Python base image. ... FROM python:3.12 COPY requirements.txt /requirements.txt RUN pip install --no-cache-dir -r requirements.txt COPY hello.py /hello.py CMD ["python", ...
🌐
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 - 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. RUN uv venv --python 3.14 /venv · With a few impure practicalities, we can really make this fast. 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 not have their versions pinned.
Find elsewhere
🌐
GitHub
github.com › astral-sh › uv › issues › 3570
`uv pip install` fails from inside docker. · Issue #3570 · astral-sh/uv
May 14, 2024 - => ERROR [builder 9/10] RUN --mount=type=ssh /root/.cargo/bin/uv pip install --system --no-cache -r requirements.txt 2.5s ------ > [builder 9/10] RUN --mount=type=ssh /root/.cargo/bin/uv pip install --system --no-cache -r requirements.txt: 2.433 error: error sending request for url (https://northamerica-northeast2-python.pkg.dev/private-pypi-418615/ritual-pypi/simple/huggingface-hub/) 2.433 Caused by: client error (Connect) 2.433 Caused by: invalid peer certificate: BadSignature ... # syntax=docker/dockerfile:1 # Comments are provided throughout this file to help you get started.
Published   May 14, 2024
Author   ArshanKhanifar
🌐
Python⇒Speed
pythonspeed.com › articles › pipenv-docker
Faster Docker builds with uv, pipenv, poetry, or pip-tools
January 17, 2025 - And now are Dockerfile looks like this: FROM python:3.12 COPY requirements.txt /tmp RUN pip install -r /tmp/requirements.txt COPY . /tmp/myapp RUN pip install /tmp/myapp CMD flask run exampleapp:app · Notice that initially we only copy ...
🌐
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. If you are running the container interactively and want to use pip then ensure you add pip to your requirements file so that it is installed in the virtual environment.
🌐
Tommasoamici
tommasoamici.com › til › how-to-use-uv-instead-of-pip-in-docker
Tommaso Amici - How to use uv instead of pip in Docker
uv is a package installer for Python written in Rust. It's a pip replacement and it's significantly faster. In CI at work replacing pip with uv in our Dockerfiles makes the build 30s faster.
🌐
GitHub
github.com › astral-sh › uv-docker-example
GitHub - astral-sh/uv-docker-example: An example of using uv in Docker images · GitHub
The Dockerfile defines the image and includes: Installation of uv · Installing the project dependencies and the project separately for optimal image build caching · Placing environment executables on the PATH · Running the web application in development mode ·
Starred by 764 users
Forked by 73 users
Languages   Dockerfile 81.4% | Shell 16.2% | Python 2.4%
🌐
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
🌐
Bneijt
bneijt.nl › blog › put-your-uv-project-inside-a-docker-container
Put your uv project inside a Docker container
December 14, 2024 - So let's jump into building a Dockerfile for a Python project maintained with uv. ... Minimize attack service by using distroless python image. For this, we will use docker BuildKit and inject our own PyPi url. So we start with: #!/bin/bash set -e rm -rf dist uv build export PIP_INDEX_URL="https://pypi.org/simple" DOCKER_BUILDKIT=1 docker build \ --secret id=pip_index_url,env=PIP_INDEX_URL \ .
🌐
Astral
docs.astral.sh › uv › getting-started › installation
Installation | uv
1 day ago - Updating uv will re-run the installer and can modify your shell profiles. To disable this behavior, set UV_NO_MODIFY_PATH=1. When another installation method is used, self-updates are disabled. Use the package manager's upgrade method instead. For example, with pip:
🌐
PyDevTools
pydevtools.com › handbook › how-to › how-to-use-uv-in-a-dockerfile
How to use uv in a Dockerfile | pydevtools
3 weeks ago - The two-stage uv sync pattern is deliberate. The first uv sync --frozen --no-install-project installs dependencies without the project itself, creating a cached Docker layer. The second uv sync --frozen installs the project after copying source code.
🌐
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 - You will need to add your ENTRYPOINT to make this work but the dependencies will be installed and calling python will use your virtual environment. If you want to learn more about multi-stage docker builds, I can highly recommend this article about multi-stage docker builds for python and also this post about using virtual environments in dockerfiles from Itamar Turner-Trauring. ... In the newest version the path to uv changes from /root/.cargo/bin/uv to /root/.local/bin/uv.