Sign inSign up

leadsdoit/postgres

By leadsdoit

Updated 8 months ago

PostgreSQL + script backup/restore

Image
Databases & storage
0

1.8K

leadsdoit/postgres repository overview

leadsdoit/postgres

This image is based on postgres:${PHP_VER}-alpine3 but with the ability to conveniently create dumps and restore from them.

Published on Docker Hub

Working with dumps

Dumps are stored in the /backup folder.

To access the created dumps, you need to mount external storage:

-v ./dump:/backup

Example docker compose

services:
    db:
        build: .
        container_name: docker_db_pgsql
        restart: always
        volumes:
            - "./db:/var/lib/postgresql/data"
            - "./dump:/backup"
        environment:
            POSTGRES_DB: ${DB_DATABASE}
            POSTGRES_USER: ${DB_USERNAME}
            POSTGRES_PASSWORD: ${DB_PASSWORD}
Create a dump

To create a backup from the database in the current container:

  • If using docker

    docker exec -it <container name> dump

  • If created via docker compose

    docker compose exec <service name> dump

Create a restore

To load a dump into the container, copy it to the mounted disk or start the container and copy it with the command:

docker cp <path to file> <container>:/backup/<dump name>

  • If using docker

    docker exec -it <container name> restore

  • If created via docker compose

    docker compose exec <service name> restore

Then choose one of the existing dumps.

Variables

Same as in the parent postgres image

POSTGRES_PASSWORD

Required. Sets the password for the main user on first container start.

POSTGRES_USER

Creates the main user on first container start. If not specified, it will be postgres.

POSTGRES_DB

Creates a database with this name on first container start. If not specified, it will equal POSTGRES_USER.

Tag summary

Content type

Image

Digest

sha256:0154dc601

Size

106.3 MB

Last updated

8 months ago

docker pull leadsdoit/postgres