Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Play with PostreSQL Through Docker

This tutorial will show you how to deploy a PostgreSQL server locally with Docker and then log into it so that you can try it out. It would be a great way to see the performance difference parallel queries can make.

Related Posts


docker run -d \
  --name my_postgres \
  -v postgresql-data:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD=password \
  -p 54320:5432 postgres:13

Get the IP address

Unfortunatley, trying to connect to your postgresql server through localhost, or your machine's private IP address won't work. Instead you need to connect to the container's IP address which you find by running:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my_postgres

Now you have the IP address (in this case, use it in the following command to log in:

psql -U postgres -h


Last updated: 25th September 2021
First published: 17th August 2020