dhi.io/timescaledb
PostgreSQL with the TimescaleDB extension for time-series data.
All examples in this guide use the public image. If you've mirrored the repository for your own use (for example, to your Docker Hub namespace), update your commands to reference the mirrored image instead of the public one.
For example:
dhi.io/timescaledb:pg17<your-namespace>/dhi-timescaledb:pg17For the examples, you must first use docker login dhi.io to authenticate to the registry to pull the images.
Published tags select both the TimescaleDB 2.x release and the PostgreSQL major. PostgreSQL 17 tags include
2.32.1-pg17, 2.32-pg17, and pg17. PostgreSQL 16 tags include 2.32.1-pg16, 2.32-pg16, and pg16. PostgreSQL 18
tags include 2.32.1-pg18, 2.32-pg18, and pg18. Every tag names the PostgreSQL major, because a data directory only
starts on the major that wrote it. Dev tags add -dev. FIPS tags add -fips. Examples below use the floating pg17
tag.
This Docker Hardened TimescaleDB image includes:
timescaledb-tune — Writes TimescaleDB and PostgreSQL configuration recommendations into postgresql.conf.timescaledb-parallel-copy — Copies rows into a TimescaleDB hypertable with parallel workers.The runtime image also includes psql and bash. The entrypoint is a bash script, so docker exec works against a
running container.
The entrypoint is /usr/local/bin/docker-entrypoint.sh. The default command is postgres, which starts the server.
Arguments after postgres are passed to the server. The server listens on port 5432/tcp. The working directory is
/. The stop signal is SIGINT, so docker stop asks PostgreSQL for a fast shutdown.
The runtime process is the postgres user, uid 70 and gid 70, the same uid as upstream's postgres user. Runtime
variants only start as uid 70: --user 0 fails because they have no gosu to drop root, and any other uid fails at
initdb because it has no passwd entry. Dev variants start as root and switch to uid 70 before the server starts. Both
distros set PG_MAJOR, PG_VERSION (the PostgreSQL major and minor version), and PGDATA, which is upstream's
/var/lib/postgresql/data for PostgreSQL 16 and 17 and /var/lib/postgresql/18/docker for PostgreSQL 18. PATH starts
with /opt/postgresql/<major>/bin. Debian also sets LANG, LANGUAGE, and LC_ALL.
POSTGRES_PASSWORD is not set in the image. Set it on the first start. POSTGRES_USER defaults to postgres, and
POSTGRES_DB defaults to POSTGRES_USER.
docker run -d --name timescaledb \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
dhi.io/timescaledb:pg17
Wait until the server accepts connections, then read the TimescaleDB extension version:
until docker logs timescaledb 2>&1 | grep -q 'ENTRYPOINT: Starting database' && docker exec timescaledb pg_isready -U postgres; do sleep 1; done
docker exec timescaledb psql -U postgres -c "SELECT extversion FROM pg_extension WHERE extname = 'timescaledb';"
Connect with psql and create a hypertable, insert one row, and count it:
docker exec -i timescaledb psql -U postgres -v ON_ERROR_STOP=1 <<'SQL'
CREATE TABLE conditions (
time timestamptz NOT NULL,
location text,
temperature double precision
);
SELECT create_hypertable('conditions', 'time');
INSERT INTO conditions (time, location, temperature) VALUES (now(), 'office', 22.5);
SELECT count(*) FROM conditions;
SQL
Remove the container when you are finished:
docker rm -f timescaledb
PGDATA exists in the image with mode 0700, owned by uid 70 and gid 70. The image does not declare volume metadata.
Mount a named volume at /var/lib/postgresql, as upstream documents, to keep the data directory across container
replacement on every PostgreSQL major. A volume from the upstream image mounted the same way opens its existing cluster.
docker volume create timescaledb-data
docker run -d --name timescaledb \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
-v timescaledb-data:/var/lib/postgresql \
dhi.io/timescaledb:pg17
until docker logs timescaledb 2>&1 | grep -q 'ENTRYPOINT: Starting database' && docker exec timescaledb pg_isready -U postgres; do sleep 1; done
docker exec timescaledb psql -U postgres -v ON_ERROR_STOP=1 -c "CREATE TABLE ticks (time timestamptz NOT NULL, value double precision); SELECT create_hypertable('ticks', 'time'); INSERT INTO ticks VALUES (now(), 1);"
docker rm -f timescaledb
Start a new container on the same volume. The row is still there:
docker run -d --name timescaledb \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
-v timescaledb-data:/var/lib/postgresql \
dhi.io/timescaledb:pg17
until docker logs timescaledb 2>&1 | grep -q 'ENTRYPOINT: Starting database' && docker exec timescaledb pg_isready -U postgres; do sleep 1; done
docker exec timescaledb psql -U postgres -c "SELECT count(*) FROM ticks;"
docker rm -f timescaledb
A bind mount of an empty root-owned host directory fails. This image runs as postgres and does not change ownership of
the mount, so initdb cannot create PGDATA in a directory owned by root. Change the host directory to uid 70 and gid
70 before you mount it:
mkdir -p timescaledb-pgdata
sudo chown 70:70 timescaledb-pgdata
docker run -d --name timescaledb \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
-v "$PWD/timescaledb-pgdata:/var/lib/postgresql" \
dhi.io/timescaledb:pg17
docker rm -f timescaledb
On an empty data directory the entrypoint initializes the cluster, sets shared_preload_libraries=timescaledb, and
creates the timescaledb extension in the postgres database, in template1, and in POSTGRES_DB. It then runs
/docker-entrypoint-initdb.d/* in lexical order. Files you mount into that directory run too, when the name ends in
.sh, .sql or .sql.gz. Server arguments given after postgres also apply while these files run.
The entrypoint also runs timescaledb-tune on that first initialization. NO_TS_TUNE is not set in the image. Set it
to any non-empty value to skip tuning.
The image sets TIMESCALEDB_TELEMETRY=off, so a new database starts with timescaledb.telemetry_level=off. Set
TIMESCALEDB_TELEMETRY=basic to opt in.
POSTGRES_HOST_AUTH_METHOD is not set in the image. Leave it unset, or set it to md5 or scram-sha-256. The values
trust and password are rejected.
This image ships the current TimescaleDB minor only. It does not include older timescaledb-*.so builds or the
timescaledb-invalidations libraries, and CREATE EXTENSION vector is not available. A data directory written by an
older TimescaleDB minor starts, but every query that touches TimescaleDB fails with
could not access file "$libdir/timescaledb-<old version>" until the extension is updated. After moving to a newer
TimescaleDB minor, including through a floating tag such as pg17, run ALTER EXTENSION timescaledb UPDATE; with
psql -X as the first command in each database that has the extension: postgres, template1, and POSTGRES_DB when
the image created it. Moving to an older minor is not supported. The image ships Debian and Alpine variants for
PostgreSQL 16, 17, and 18, each with FIPS variants. Alpine tags add -alpine3.24, for example pg17-alpine3.24.
Runtime images do not include a package manager. PL/Python is not included.
timescaledb-tune and timescaledb-parallel-copy are on PATH and at /usr/local/bin. Override the entrypoint to
print each version:
docker run --rm --entrypoint timescaledb-tune dhi.io/timescaledb:pg17 --version
docker run --rm --entrypoint timescaledb-parallel-copy dhi.io/timescaledb:pg17 --version
Docker Hardened Images come in different variants depending on their intended use. Image variants are identified by their tag.
Runtime variants are designed to run your application in production. These images are intended to be used either directly or as the FROM image in the final stage of a multi-stage build. These images typically:
Build-time variants typically include dev in the tag name and are intended for use in the first stage of a
multi-stage Dockerfile. These images typically:
FIPS variants include fips in the variant name and tag. They come in both runtime and build-time variants. These
variants use cryptographic modules that have been validated under FIPS 140, a U.S. government standard for secure
cryptographic operations. For example, usage of MD5 fails in FIPS variants.
To view the image variants and get more information about them, select the Tags tab for this repository, and then select a tag.
To migrate your application to a Docker Hardened Image, you must update your Dockerfile. At minimum, you must update the base image in your existing Dockerfile to a Docker Hardened Image. This and a few other common changes are listed in the following table of migration notes.
| Item | Migration note |
|---|---|
| Base image | Replace your base images in your Dockerfile with a Docker Hardened Image. |
| Package management | Non-dev images, intended for runtime, don't contain package managers. Use package managers only in images with a dev tag. |
| Non-root user | By default, non-dev images, intended for runtime, run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. |
| Multi-stage build | Utilize images with a dev tag for build stages and non-dev images for runtime. For binary executables, use a static image for runtime. |
| TLS certificates | Docker Hardened Images contain standard TLS certificates by default. There is no need to install TLS certificates. |
| Ports | Non-dev hardened images run as a nonroot user by default. As a result, applications in these images can't bind to privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. To avoid issues, configure your application to listen on port 1025 or higher inside the container. |
| Entry point | Docker Hardened Images may have different entry points than images such as Docker Official Images. Inspect entry points for Docker Hardened Images and update your Dockerfile if necessary. |
| No shell | By default, non-dev images, intended for runtime, don't contain a shell. Use dev images in build stages to run shell commands and then copy artifacts to the runtime stage. |
The following steps outline the general migration process.
Find hardened images for your app.
A hardened image may have several variants. Inspect the image tags and find the image variant that meets your needs.
Update the base image in your Dockerfile.
Update the base image in your application's Dockerfile to the hardened image you found in the previous step. For
framework images, this is typically going to be an image tagged as dev because it has the tools needed to install
packages and dependencies.
For multi-stage Dockerfiles, update the runtime image in your Dockerfile.
To ensure that your final image is as minimal as possible, you should use a multi-stage build. All stages in your
Dockerfile should use a hardened image. While intermediary stages will typically use images tagged as dev, your
final runtime stage should use a non-dev image variant.
Install additional packages
Docker Hardened Images contain minimal packages in order to reduce the potential attack surface. You may need to install additional packages in your Dockerfile. Inspect the image variants to identify which packages are already installed.
Only images tagged as dev typically have package managers. You should use a multi-stage Dockerfile to install the
packages. Install the packages in the build stage that uses a dev image. Then, if needed, copy any necessary
artifacts to the runtime stage that uses a non-dev image.
For Alpine-based images, you can use apk to install packages. For Debian-based images, you can use apt-get to
install packages.
The following are common issues that you may encounter during migration.
The hardened images intended for runtime don't contain a shell nor any tools for debugging. The recommended method for debugging applications built with Docker Hardened Images is to use Docker Debug to attach to these containers. Docker Debug provides a shell, common debugging tools, and lets you install other tools in an ephemeral, writable layer that only exists during the debugging session.
By default image variants intended for runtime, run as the nonroot user. Ensure that necessary files and directories are accessible to the nonroot user. You may need to copy files to different directories or change permissions so your application running as the nonroot user can access them.
Non-dev hardened images run as a nonroot user by default. As a result, applications in these images can't bind to
privileged ports (below 1024) when running in Kubernetes or in Docker Engine versions older than 20.10. To avoid issues,
configure your application to listen on port 1025 or higher inside the container, even if you map it to a lower port on
the host. For example, docker run -p 80:8080 my-image will work because the port inside the container is 8080, and
docker run -p 80:81 my-image won't work because the port inside the container is 81.
By default, image variants intended for runtime don't contain a shell. Use dev images in build stages to run shell
commands and then copy any necessary artifacts into the runtime stage. In addition, use Docker Debug to debug containers
with no shell.
Docker Hardened Images may have different entry points than images such as Docker Official Images. Use docker inspect
to inspect entry points for Docker Hardened Images and update your Dockerfile if necessary.