Containers

Run PostgreSQL in Docker

A local Postgres database in one command, with its data kept safe between restarts.

Fill these in once
  1. Start Postgres
    Terminal
    docker run --name postgres -e POSTGRES_PASSWORD=devpassword -p 5432:5432 -v pgdata:/var/lib/postgresql/data -d postgres:17

    Your data lives in the pgdata volume, so it survives restarts.

  2. Open a SQL prompt inside it
    Terminal
    docker exec -it postgres psql -U postgres

    Type \q to leave.

  3. Stop and start it later
    Terminal
    docker stop postgres && docker start postgres

Check it worked

  1. Check it's running
    Terminal
    docker ps --filter name=postgres

    Connect from your app with postgresql://postgres:@localhost:5432/postgres

Undo it
  1. Remove the container and its data
    Terminal
    docker rm -f postgres && docker volume rm pgdata
  1. Start Postgres
    Terminal · Ubuntu / Debian
    docker run --name postgres -e POSTGRES_PASSWORD=devpassword -p 5432:5432 -v pgdata:/var/lib/postgresql/data -d postgres:17

    Your data lives in the pgdata volume, so it survives restarts.

  2. Open a SQL prompt inside it
    Terminal · Ubuntu / Debian
    docker exec -it postgres psql -U postgres

    Type \q to leave.

  3. Stop and start it later
    Terminal · Ubuntu / Debian
    docker stop postgres && docker start postgres

Check it worked

  1. Check it's running
    Terminal · Ubuntu / Debian
    docker ps --filter name=postgres

    Connect from your app with postgresql://postgres:@localhost:5432/postgres

Undo it
  1. Remove the container and its data
    Terminal · Ubuntu / Debian
    docker rm -f postgres && docker volume rm pgdata
  1. Start Postgres
    PowerShell
    docker run --name postgres -e POSTGRES_PASSWORD=devpassword -p 5432:5432 -v pgdata:/var/lib/postgresql/data -d postgres:17

    Your data lives in the pgdata volume, so it survives restarts.

  2. Open a SQL prompt inside it
    PowerShell
    docker exec -it postgres psql -U postgres

    Type \q to leave.

  3. Stop and start it later
    PowerShell
    docker stop postgres; docker start postgres

Check it worked

  1. Check it's running
    PowerShell
    docker ps --filter name=postgres

    Connect from your app with postgresql://postgres:@localhost:5432/postgres

Undo it
  1. Remove the container and its data
    PowerShell
    docker rm -f postgres; docker volume rm pgdata