Django container complains "error walking file system" when venv is installed
See original GitHub issueWhat happened?
After creating a fresh project, and then docker-compose build
and up
, The Django Docker container infinitely complains “error walking file system”.
What should’ve happened instead?
The Django container should start without any errors.
Additional details
This happens if you have a Python venv
environment installed anywhere inside the project directory. The problem is, inside the docker container, venv symlinks to files that don’t exist in the container (e.g. /usr/bin/python3.8
). I have a venv
to test changes to requirements locally instead of waiting for a docker-compose build to fail (which takes a lot longer).
Steps to reproduce
Inside a new or existing cookiecutter project directory
docker-compose -f local.yml build
docker-compose -f local.yml up
Stop the containers (ctrl-c). Now, create a new python venv
python -m venv venv
Now bring up your containers and the Django Container will constantly complain “error walking file system”:
docker-compose -f local.yml up
I assume this is watchgod
complaining. Let me know if this is correct or not.
If you’re open to a fix for this issue, I’ll open a pull request to update the Dockerfile and fix this problem.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:19
I test your solution and works without problems, only make a change that volume must be a absolutly path, change
volumes: - .:/app - /app/venv/
add a/
beforeapp
I had the same problem, here is how I solved it.
In a docker container there is no need to create a virtual environment, since docker is akin to a virtual environment, so in a container we can
pip install
all packages globally. So when we spin up a container with adocker compose up
, mapping an app folder from the host to a folder in a container, it is important to omit mapping the venv folder from the host, otherwise python gets confused, since now there is a symlink forapp/venv/bin/python
inside a container pointing to a python interpreter location from the host operating system. So a way to omit mapping venv from the host to a container is add this into docker-compose: