Configuring the databases
We continue adding services in docker-compose.yaml
. After the Django service, we add the following configuration:
postgresql: image: postgres environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: hello_db volumes: - ./postgres_data:/var/lib/postgresql/data/ expose: - 5432
In image: postgres
, we are using the official PostgreSQL image. It will be automatically downloaded from the official repositories. Next, we configure the environment variables to indicate the user credentials (POSTGRES_USER
and POSTGRES_PASSWORD
) and the name of the database (POSTGRES_DB
). The variables must match those declared in the Django service; otherwise, it will fail to connect....