I was not able to edit my comment again.
So first of all you need to combine your containers in one docker network, see here. An example docker-compose would look like that:
version: "3.9"
services:
db:
image: postgres:9.6
environment:
- POSTGRES_DB=my database
- POSTGRES_USER=my user
- POSTGRES_PASSWORD=my password
networks:
- backend
web:
build: .
command: python3 manage.py runserver 127.0.0.1:8080
volumes:
- .:/code
ports:
- "8080:8080"
depends_on:
- db
networks:
- backend
networks:
backend:
driver: bridge
name: backend
Then you need to edit your django settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'my database',
'USER': 'my user',
'PASSWORD': 'my password',
'HOST': '<your-service-name should be "db">',
'PORT': 5432,
}
}
In your current settings, the django tries to connect to a database, that is running within in the same container, what is not the case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…