Redrock Postgres Documentation
Home Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Docker Image Installation

Redrock Postgres provides Docker images based on Debian Linux tailored for the x86 hardware architecture. You can pull and use the Docker image corresponding to your required version.

This Docker image is built on top of the official PostgreSQL Docker image. Complete documentation for the image can be found in the GitHub repository.

Installing the Package

Pulling the Docker Image

Pull the Docker image for the specified Redrock Postgres version:

docker pull redrockpg/postgres:18.6-debian13

Running Redrock Postgres

Start a Redrock Postgres instance:

docker run --name mypg \
  -e POSTGRES_PASSWORD=mysecretpassword \
  -d redrockpg/postgres:18.6-debian13

In the command above, 18.6-debian13 represents the Redrock Postgres version number and the operating system version number.

Installation Layout

A standard installation of Redrock Postgres using the Docker image result in files and resources created under the system directories, shown in the following table.

Table 1. Redrock Postgres Installation Layout

Files or Resources Location
Executables /usr/pgsql-<version>/bin
Libraries /usr/pgsql-<version>/lib
Server and contrib documentation /usr/pgsql-<version>/doc
Data /var/lib/pgsql/<version>/data
Templates and other shared data /usr/pgsql-<version>/share

In the table above, the value of version represents the PostgreSQL version number (for example, 18).

The installation will also create a user named postgres and a group named postgres on the system.

Manage Containerized Instances

Connect to the server via psql:

docker exec -ti mypg psql -U postgres

Stop the server:

docker stop mypg

Start the server:

docker start mypg

Remove container:

docker rm mypg

Supported Environment Variables

When starting a Redrock Postgres instance with the Docker image, we can configure installation settings for the postgres container by using environment variables. The PostgreSQL image provides several environment variables, among which POSTGRES_PASSWORD is the only required variable; all others are optional.

Warning: the Docker specific variables will only have an effect if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.

POSTGRES_PASSWORD

This environment variable is required for you to use the PostgreSQL image. It must not be empty or undefined. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER environment variable.

POSTGRES_USER

This optional environment variable is used in conjunction with POSTGRES_PASSWORD to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of postgres will be used.

Be aware that if this parameter is specified, PostgreSQL will still show The files belonging to this database system will be owned by user "postgres" during initialization. This refers to the Linux system user (from /etc/passwd in the image) that the postgres daemon runs as, and as such is unrelated to the POSTGRES_USER option.

POSTGRES_DB

An optional environment variable used to specify the default database name created when the image is started for the first time. If omitted, the value of POSTGRES_USER is used as the database name by default.

POSTGRES_INITDB_ARGS

An optional environment variable used to pass additional arguments to the initdb command during database initialization. Its value is a space-separated string formatted identically to initdb command arguments. For example, to enable data page checksums, you can specify: -e POSTGRES_INITDB_ARGS="--data-checksums".

POSTGRES_INITDB_WALDIR

An optional environment variable used to specify the storage location for PostgreSQL transaction logs (WAL). By default, transaction logs are stored in a subdirectory of the main PostgreSQL data directory (PGDATA). In certain scenarios, storing transaction logs on a storage device with different performance or reliability characteristics can improve overall performance.

POSTGRES_HOST_AUTH_METHOD

An optional environment variable used to control the host connection authentication method for all databases, all users, and all addresses. If omitted, versions 14+ default to scram-sha-256 password authentication (older versions used md5). During empty database initialization, this variable is written to pg_hba.conf using roughly the following logic:

echo "host all all all $POSTGRES_HOST_AUTH_METHOD" >> pg_hba.conf

For allowed values and their meanings, refer to the description of pg_hba.conf in the official PostgreSQL documentation.

PGDATA

The path corresponding to the image’s PGDATA environment variable is /var/lib/pgsql/18/data. Meanwhile, the declared VOLUME path is /var/lib/pgsql. Please use the declared VOLUME path when mounting data volumes. This allows users performing major PostgreSQL version upgrades to mount /var/lib/pgsql and use pg_upgrade in --link mode for faster upgrades.

This (PGDATA) is an environment variable that is not Docker specific. Because the variable is used by the postgres server binary (see the PostgreSQL documentation), the entrypoint script takes it into account.

Docker Secrets

As an alternative to passing sensitive information via environment variables, _FILE may be appended to some of the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container. In particular, this can be used to load passwords from Docker secrets stored in /run/secrets/<secret_name> files. For example:

docker run --name mypg \
  -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd \
  -d redrockpg/postgres:18.6-debian13

Currently, this is only supported for POSTGRES_INITDB_ARGS, POSTGRES_PASSWORD, POSTGRES_USER, and POSTGRES_DB.