6👍
✅
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
3👍
You should include additional volume to preserve your mediafiles folder:
- /path/to/store/on/host:/path/to/mediafiles
- Docker + Django + Postgres Add-on + Heroku
- How to access get request data in django rest framework
- Django not matching unicode in url
- Ignore a specific test using Django
- Django – missing 1 required positional argument: 'request'
2👍
Leaving a compose file here. I am persisting the DB, media and elastic search data. This should be useful for those who have a hard time figuring where to place what the current answers here give.
version: '3.3'
services:
# elastic search service
elasticsearch:
image: elasticsearch:6.5.4
ports:
- '9400:9200'
volumes:
- elastic-data:/usr/share/elasticsearch/data
# Postgres database service
postgres:
image: postgres:9.6-alpine
environment:
POSTGRES_DB: dilirena
POSTGRES_USER: dilirenauser
POSTGRES_PASSWORD: pa55w0rd
ports:
- '5435:5432'
volumes:
- postgres-data:/var/lib/postgresql/data
# drf restful api service
api:
build: .
command: python manage.py runserver 0.0.0.0:8081
volumes:
- .:/app
- media:<media-path>
ports:
- '8081:8081'
env_file:
- ./.env
links:
- postgres
- elasticsearch
depends_on:
- postgres
- elasticsearch
volumes:
elastic-data:
postgres-data:
media:
I am on mac, not sure if it makes a difference.
Source:stackexchange.com