cookiecutter-django: Django container complains "error walking file system" when venv is installed
What 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.
About this issue
- Original URL
- State: open
- 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:In my case, @bryanus1 's solution worked:
@jmoppel I was unable to reproduce the issue. What operating system are you using?
If you want, could you please record the steps you made in the terminal using https://asciinema.org/ and after sending the recording link? (Be careful to avoid showing things that could compromise security, such as passwords, tokens, etc.)
Install asciinema
Create an account to able to manage your asciinema records
Start record the steps
Note: if you just want to learn how to use asciinema but without uploading the recording, I recommend forcing the recording to a local file by entering a file-name for the recording
to watch the recording, just run
to upload to your account on https://asciinema.org/