Install docker

See reference.computers.setup.docker-install

Create docker-compose.yml

Add the following to docker-compose.yml

 1version: '3'
 2services:
 3  db:
 4    container_name: pgcontainer
 5    image: postgres:14.1-alpine
 6    restart: always
 7    environment:
 8      - POSTGRES_USER=postgres
 9      - POSTGRES_PASSWORD=postgres
10    ports:
11      - '5432:5432'
12    volumes: 
13      - ./db-data:/var/lib/postgresql/data
14  pgadmin:
15    container_name: pgadmin4_container
16    image: dpage/pgadmin4
17    restart: always
18    environment:
19      - PGADMIN_DEFAULT_EMAIL=your@email.addr
20      - PGADMIN_DEFAULT_PASSWORD=supersecret
21    ports:
22      - '5050:80'

The pgadmin part is optional. If present, pgadmin can be accessed by visiting localhost:5050 and using the PGADMIN_DEFAULT_* variable values for logging in.

Then docker-compose up -d

Access psql command line client

docker exec -it pgcontainer psql -U postgres

OR

docker exec -it pgcontainer /bin/sh and then in the prompt that appears

psql --username postgres