I'm using Django cookiecutter with docker and docker-compose.
On production I'm using dj-static to serve my media files.
Whenever I use 'docker-compose down' command everything that is in my media volume gets deleted. I think this is the expected outcome of that command but everything that is in 'postgreSQL' is kept.
How can I do that with the 'media' volume?
I've managed to make this work.
In the docker-compose.yml I've added:
volumes:
media: {}
django:
....
volumes:
- media:/app/project-name/same-path-as-MEDIA_URL
In the compose/django Dockerfile I've added:
VOLUME /app/PROJECT_NAME/same-path-as-MEDIA_URL
After this changes I've run docker-compose build, docker-compose up and got a 500 error. To pass this (if you haven't modified django cookiecutter's default settings):
docker ps - here you'll get your django container id
docker exec -u root THE_CONTAINER_ID chown django:user PROJECT_NAME/same-path-as-MEDIA_URL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With