Database creation with Docker

Now, we will have a real database to save our entities.

We will use Docker to have a container for a Postgres database. Create, at the root of the project, the file docker-compose.yml with following content

version: '3'

services:
  database:
    image: postgres
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_PASSWORD: pass123

We are writing our database password in plain text. This is a security flaw. In the Configuration section, we'll learn how to fix this issue.

To turn on the container, use the following command

docker-compose up -d

If you want to turn it off at some point, just use

docker-compose down

Finally, to access our database, we can use pgAdmin. We shall register a server with the following settings

  • Name - Conrod

  • Host name/address - localhost

  • Port - 5432

  • Password - pass123

  • Save password? - Yes

Commit - Creating database

Last updated