Definitive Notes on Docker and Postgres

Every once in a while I have to spin up a postgres dockerize instance to play around, and since 2017 it’s been a pain having to go through the docs just to get things working.
So now this is where I’m going to come back whenever I need to do that.

Creating the Container

docker run \
--name strapi-postgres \
-p 5432:5432 \
-e POSTGRES_PASSWORD=mycustompassword \
-e POSTGRES_USER=mycustomuser -d postgres
-e POSTGRES_DB=mycustomdatabase

Connecting via psql

sudo apt install postgresql # for ubuntu/debian based
psql -h localhost -p 5432 -U mycustomuser

Bonus: connecting from inside the container itself

docker exec -it strapi-postgres bash # opens shell in container
psql -U mycustomuser # won't even ask for password.

Jack Of All Trades