Thanks for the detailed docker docs! I'm trying to use uv in docker compose for local development. Trying to bind mount my application code and an anonymous volume for app/.venv. This is similar to the approach shown in docs with docker run which aims to avoid overwriting host vs docker container venv files, and keep them separate.
Sadly, uv sync inside the container errors with:
error: Project virtual environment directory /app/.venv cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment
This might be because uv tries to replace the .venv folder, but it can't since it's a volume?
Docker compose settings
services:
reproduce:
build:
context: .
dockerfile: Dockerfile
entrypoint: "tail -f /dev/null"
volumes:
- ./:/app
- /app/.venv
Details
- version: uv 0.5.4
- OS: debian 12
Reproducible setup
git clone git@github.com:ben-xD/reproduce-uv-docker-compose-error.git
docker-compose up -d
- Enter shell:
docker exec -it uv-reproduce-error-reproduce-1 bash
- Run uv:
uv sync
- Observe error:
error: Project virtual environment directory `/app/.venv` cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment
Following documentation's docker run
I also tried following the docs, by running:
docker run -it --rm --volume .:/app --volume /app/.venv uv-reproduce-error-reproduce bash
Then running
but i get the same error:
root@ea61fab74354:/app# uv sync
Using CPython 3.11.10
error: Project virtual environment directory `/app/.venv` cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment
Thanks for the detailed docker docs! I'm trying to use uv in docker compose for local development. Trying to bind mount my application code and an anonymous volume for
app/.venv. This is similar to the approach shown in docs withdocker runwhich aims to avoid overwriting host vs docker container venv files, and keep them separate.Sadly,
uv syncinside the container errors with:This might be because uv tries to replace the
.venvfolder, but it can't since it's a volume?Docker compose settings
Details
Reproducible setup
git clone git@github.com:ben-xD/reproduce-uv-docker-compose-error.gitdocker-compose up -ddocker exec -it uv-reproduce-error-reproduce-1 bashuv syncFollowing documentation's docker run
I also tried following the docs, by running:
Then running
but i get the same error: