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 postgressets the container name topostgres
-e POSTGRES_PASSWORDsets the default password for thepostgresuser
-p 5432:5432maps container port 5432 to your local port 5432
-druns 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.