Docker and Django manage.py
I’m trying to find a workflow with Docker and Django. Currently, I’m using the basic configuration from the docker documentation.
I’d like to use
manage.py startapp directly from the container to start a new app using:
docker-compose run web ./manage.py startapp myapp
But all the files created in the volume are owned by the root user and not by myself, so I can’t edit them from the host.
My idea is to avoid installing all the requirements on my host machine but maybe I should not create app from the container?
One possible solution is to create a user and make it having the same UID/GID than my user on my host machine but it won’t work if I try to use an other account on my host machine…
One Solution collect form web for “Docker and Django manage.py”
What worked best for me was avoiding (or minimizing) file creation inside the containers.
My Dockerfile would just copy the requirements.txt and install them;
and the container would access the app files through a mounted volume.
I pass the env var
PYTHONDONTWRITEBYTECODE=1 to the containers, so python does not create
The few times I cannot avoid it (like,
./manage.py makemigrations), I run
It’s not ideal, but as this happens rarely for my case, I don’t bother.