← All posts

How to run PostgreSQL in Docker

Need a PostgreSQL database up and running fast? Docker makes it easy. Here’s how I do it in three steps.

Step 1 — Pull the image

docker pull postgres

Step 2 — Create the container

docker run --name postgres -e POSTGRES_PASSWORD=MySuperStrongP@ssw0rdLol -p 5432:5432 -d postgres

Here’s what each part does:

--name postgres sets the container name to postgres

-e POSTGRES_PASSWORD sets the default password for the postgres user

-p 5432:5432 maps container port 5432 to your local port 5432

-d runs the container in detached mode

Step 3 — Connect to it

host: localhost

port: 5432

username: postgres

password: <password from step 2>

Connect to your PostgreSQL container with your favorite database client, like PgAdmin or DBeaver.