escamil - Hugo deployed website

Rob's Menagerie (recipes and such)

Docker Deployment

Installing PostgreSQL using Docker Desktop

Time requirement: 10 mins

Install Docker Desktop

Mac Install Notes / Win Install Notes

Summary:

  1. download package from official Docker release notes page
  2. Accept license and proceed with installation
  3. Optionally review Docker Desktop explorer tutorial

Deploy Postgres-17 install and expose ports

  • Download latest Postgres “container”:
    $ docker pull postgres:latest

  • or install specific/named version:
    $ docker pull postgres:17.4

Launch Postgres Container with exposed port

docker run -d --name pgdemo -p 5432:5432 -e POSTGRES_PASSWORD=DefaultPassword postgres:latest

or for named postgres version:

docker run -d --name pgdemo -p 5432:5432 -e POSTGRES_PASSWORD=DefaultPassword postgres:17.4

“-d” is for detached session, “-e” are for environment variables

Connect to local Postgres Instance

  • Using Docker session in docker environment:
    docker exec -it pgdemo psql -U postgres -d postgres

  • Using exposed port with local shell access:
    psql -h localhost -U "postgres" -d postgres

Install via YAML file

Ephemeral instance created within docker environment for automated deployments

Create YAML config file

Create a compose.yaml with the following content:

# sample from offical docker repo
# hub.docker.com/_/postgres

services :
  db:
    image: postgres:17.5-alpine
    restart: always
    shm_size: 128mb
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: {username}
      POSTGRES_PASSWORD: {password}
      POSTGRES_DB: sample
  admin:
    image: adminer
    restart: always
    depends_on:
      - db
    ports:
      - 8080:8080

use link in references section to determine latest postgres image
the alpine version consumes the fewest resources.

execute the command below to begin services:

docker compose up

Control-C will stop services, or use the [–detach] switch

Connect to Services

Services can be used in various ways:

  • via CLI: psql -h {hostname} -U "{username}" -d sample
  • via docker: docker exec -it {container_name} psql -U {username} -d sample
  • via adminer: http://{hostname}:8080 server: db

find container name via docker ps -a

References

Last updated on 28 Apr 2025
Published on 28 Apr 2025