Postgres + Docker Compose for local development

Ben-Hur Santos Ott
1 min readFeb 18, 2020

Heeeellooo beloved heroes!

Today we will learn how to configure a Postgres database using docker-compose with an initial populated database!

First, let’s create the docker-compose file:

Let’s analyze some points here:

  • environment: the POSTGRES_PASSWORD and POSTGRES_USER are the credentials to access the database on the localhost.
  • ports: the database will be available in port 5432.
  • volumes: we are mapping two values here: the ./init-db/init-db.sql is the path of the script SQL in your machine. When the database is created, it will run this script. You can create tables, insert data, etc.

Now you just need to run docker-compose up -d postgres and that’s it!

See you o/

--

--