Sign inSign up

ymnik13/postgres

By ymnik13

•Updated 2 months ago

PostgreSQL + script backup/restore

Image
Databases & storage
0

4.0K

ymnik13/postgres repository overview

⁠ymnik13/postgres

A multi-platform PostgreSQL image based on the official Alpine image, with helper commands for creating and restoring database backups.

The image is available on Docker Hub⁠.

⁠Supported versions

PostgreSQLVersion tagMajor tagAdditional tag
16.14ymnik13/postgres:16.14ymnik13/postgres:16—
17.10ymnik13/postgres:17.10ymnik13/postgres:17—
18.4ymnik13/postgres:18.4ymnik13/postgres:18ymnik13/postgres:latest

All tags support the following Linux platforms:

  • 386
  • amd64
  • arm/v6
  • arm/v7
  • arm64
  • ppc64le
  • s390x

⁠Usage

services:
  db:
    image: ymnik13/postgres:18
    container_name: docker_db_pgsql
    restart: always
    volumes:
      - "./db:/var/lib/postgresql"
      - "./dump:/backup"
    environment:
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      TZ: ${TZ}
    ports:
      - "127.0.0.1:5451:5432"
⁠Data directory

PostgreSQL 18 and later use a version-specific data directory at /var/lib/postgresql/<major>/docker. Mount persistent storage at /var/lib/postgresql:

volumes:
  - "./db:/var/lib/postgresql"

For PostgreSQL 17 and earlier, mount persistent storage at /var/lib/postgresql/data:

volumes:
  - "./db:/var/lib/postgresql/data"

⁠Backups

Backup files are stored in /backup. Mount a local directory there to keep them outside the container:

docker run --detach \
  --name postgres \
  --env POSTGRES_PASSWORD=change-me \
  --volume "./db:/var/lib/postgresql" \
  --volume "./dump:/backup" \
  ymnik13/postgres:18
⁠Create a backup

Run the dump helper in an existing container:

docker exec -it <container-name> dump

With Docker Compose:

docker compose exec <service-name> dump

The command creates a custom-format PostgreSQL backup named <database>_backup_<timestamp>.dump in /backup.

⁠Restore a backup

If the backup directory is not mounted, copy the backup into the container first:

docker cp <backup-file> <container-name>:/backup/<backup-name>.dump

Start the interactive restore helper and select a backup from the list:

docker exec -it <container-name> restore

With Docker Compose:

docker compose exec <service-name> restore

⁠Environment variables

The image supports all variables provided by the official PostgreSQL image⁠, including:

  • POSTGRES_PASSWORD — password for the initial PostgreSQL superuser;
  • POSTGRES_USER — name of the initial superuser, defaults to postgres;
  • POSTGRES_DB — name of the initial database, defaults to the value of POSTGRES_USER;
  • TZ — container time zone.

⁠Publishing

Log in to Docker Hub before publishing:

docker login

Build and publish the complete supported version matrix:

bash ./publish-all.sh

Build and publish one version with both its version and major tags:

bash ./publish.sh 17.10

Pass -l to update the latest tag as well:

bash ./publish.sh 18.4 -l

The publishing scripts accept these optional environment variables:

VariableDefaultDescription
NAME_IMAGEymnik13/postgresTarget image repository
ALPINE_VERSION3.24Alpine version used by the base image
PLATFORMSAll platforms listed aboveComma-separated build platform list

For example, to publish an AMD64-only build:

PLATFORMS=linux/amd64 bash ./publish.sh 18.4

Tag summary

Content type

Image

Digest

sha256:32323e3af…

Size

120.9 MB

Last updated

2 months ago

docker pull ymnik13/postgres