I am trying to dockerize my Django project. For this purpose, I am trying to divide the whole project into 2 parts
- The whole web related things in one container.
- Database i.e Postgres in another
I am creating the Postgres database container using command:
docker run --name postgres -it -e POSTGRES_USER=username -e POSTGRES_PASSWORD=mysecretpassword postgres
When this postgres instance started running I entered the shell postgres instance using:
docker exec -it postgres /bin/bash
root@ae052fbce400:/# psql -U psql
Inside Psql shell that i got, I am creating the Database named DBNAME and granted all the privileges to username;
Database settings inside the webapp container is:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DBNAME',
'USER': 'username',
'PASSWORD': 'mysecretpassword',
'HOST': 'postgres',
'PORT': 5432
}
}
Here is my docker-compose.yml file
services:
web:
image: 1ce04167758d #image build of webapp container
command: python manage.py runserver
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- postgres
postgres:
image: postgres
env_file:
- .env
expose:
- "5432"
When I ran docker-compose up I am getting the following error:-
web_1 | django.db.utils.OperationalError: FATAL: password authentication failed for user "username"