I am trying to dockerize my Django application with its PostgreSQL database.
I have the following config files: docker-compose.yml
version: '3'
services:
web:
container_name: web
build:
context: .
dockerfile: Dockerfile
env_file:
- csgo.env
environment:
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- '8000:8000'
volumes:
- .:/code
depends_on:
- postgres_db
postgres_db:
container_name: postgres_db
image: postgres:13
env_file:
- csgo.env
environment:
- POSTGRES_DB='postgres'
- POSTGRES_NAME='postgres'
- POSTGRES_USER='postgres'
- POSTGRES_PASSWORD='postgres'
- POSTGRES_HOST='postgres_db'
- POSTGRES_PORT='5432'
ports:
- '5432:5432'
csgo.env
POSTGRES_DB='postgres'
POSTGRES_NAME='postgres'
POSTGRES_USER='postgres'
POSTGRES_PASSWORD='postgres'
POSTGRES_HOST='postgres_db'
POSTGRES_PORT='5432'
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'postgres_db',
'PORT': '5432',
}
}
I get the most typical error:
web | File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 122, in connect
web | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
web | django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"
web |
What is the problem? What did I miss? Why this error occurs, if everything appear working fine?
Note: I know this kind of question is popular on the Internet. But no one of them has answer to my question. Because my question is probably about mistake I have made (or a type) which I can't figure out for a whole day. Please help!