https://gitlab.com/tozd/docker/postgresql
Available as:
tozd/base ← tozd/dinit ← tozd/postgresql
9.3: PostgreSQL 9.39.4: PostgreSQL 9.49.5: PostgreSQL 9.59.6: PostgreSQL 9.610: PostgreSQL 1011: PostgreSQL 1112: PostgreSQL 1213: PostgreSQL 1314: PostgreSQL 1415: PostgreSQL 1516: PostgreSQL 1617: PostgreSQL 1718: PostgreSQL 18
/var/log/postgresql: Log files whenLOG_TO_STDOUTis not set to1./var/lib/postgresql: Persist this volume to not lose state.
To optionally initialize at the first startup:
PGSQL_ROLE_1_USERNAME: Username of a user to create.PGSQL_ROLE_1_PASSWORD: Password for the created user.PGSQL_ROLE_1_FLAGS: Any flags at user creation. Default isLOGIN.PGSQL_DB_1_NAME: Name of a database to be created.PGSQL_DB_1_OWNER: Username of the owner of the database. Must be set for database creation to work.PGSQL_DB_1_ENCODING: Encoding for the database. Default isUNICODE.PGSQL_DB_1_LC_COLLATE: Collation order for the database. Default is empty.PGSQL_DB_1_LC_CTYPE: Character classification for the database. Default is empty.PGSQL_DB_1_TEMPLATE: Name of the template from which to create the new database. Default isDEFAULT.PGSQL_DB_1_POSTGIS: If set, PostGIS will be installed in the database.
Other:
LOG_TO_STDOUT: If set to1output logs to stdout (retrievable usingdocker logs) instead of log volumes.
5432/tcp: Port on which PostgreSQL listens.
Image providing PostgreSQL SQL server.
Different Docker tags provide different PostgreSQL versions.
You should make sure you mount data volume (/var/lib/postgresql) so that you do not
lose database data when you are recreating a container. If a volume is empty, image
will initialize it at the first startup.
If you are extending this image, you can add a script /etc/service/postgresql/run.initialization
which will be run at a container startup, after the container is initialized, but before the
PostgreSQL daemon is run.
When LOG_TO_STDOUT is set to 1, Docker image logs output to stdout and stderr. All stdout output is JSON.
There are two ways to use this image. As a database which is shared between multiple other services and that you create databases and users accordingly. Or as a database just for one user/app.
After first run, you can connect to the PostgreSQL as an administrator from the inside
the container, for example, for a container named postgresql:
$ docker exec -t -i postgresql /bin/bash
$ psql -U postgres postgres
You can create users:
$ createuser -U postgres -DRS -PE <USERNAME>
You can create a database:
$ createdb -U postgres -O <USERNAME> <DBNAME>
You can install PostGIS into your database by connecting to it and running:
> CREATE EXTENSION postgis;
You can backup a database from outside the container:
$ docker exec postgresql pg_dump -Fc -U postgres <DBNAME> > /var/backups/<DBNAME>.pgdump
You can restore a database from outside the container:
$ cat /var/backups/<DBNAME>.pgdump | docker exec -i postgresql pg_restore -Fc -U postgres -d <DBNAME>
When data volume is initialized at the first startup, you can instruct the image to automatically create an user and/or a database by passing environment variables to a container.
There is also a read-only GitHub mirror available, if you need to fork the project there.