I'm trying to dockerize my Django project, but my database container seems to not be working. When I initialize docker-compose up
the server starts but there is a message telling me I have 53 unapplied migrations (all), and run python manage.py migrate
to migrate (like it is a blank database). My docker-compose looks like this:
services:
db:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=database_name
- POSTGRES_USER=database_admin
- POSTGRES_PASSWORD=pskfnbiu42834h
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
environment:
- POSTGRES_DB=database_name
- POSTGRES_USER=database_admin
- POSTGRES_PASSWORD=pskfnbiu42834h
depends_on:
- db
And I changed my settings.py DATABASE
to this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get('POSTGRES_NAME'),
'USER': os.environ.get('POSTGRES_USER'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
'HOST': 'db',
'PORT': '5432',
}
}
I think the problem might have to do with the volumes
part. Docker created a data
folder in my project directory with PostgreSQL
related files. Where do those /var/lib/
folder live? Anyone can give any orientation?