PostgreSQL + script backup/restore
2.7K
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.
| PostgreSQL | Version tag | Major tag | Additional tag |
|---|---|---|---|
| 16.14 | ymnik13/postgres:16.14 | ymnik13/postgres:16 | — |
| 17.10 | ymnik13/postgres:17.10 | ymnik13/postgres:17 | — |
| 18.4 | ymnik13/postgres:18.4 | ymnik13/postgres:18 | ymnik13/postgres:latest |
All tags support the following Linux platforms:
386amd64arm/v6arm/v7arm64ppc64les390xservices:
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"
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"
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
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.
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
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.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:
| Variable | Default | Description |
|---|---|---|
NAME_IMAGE | ymnik13/postgres | Target image repository |
ALPINE_VERSION | 3.24 | Alpine version used by the base image |
PLATFORMS | All platforms listed above | Comma-separated build platform list |
For example, to publish an AMD64-only build:
PLATFORMS=linux/amd64 bash ./publish.sh 18.4
Content type
Image
Digest
sha256:32323e3af…
Size
120.9 MB
Last updated
about 2 months ago
docker pull ymnik13/postgres