NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
DOCS / DOCKER RECIPES / COMPOSE BASIC

Compose basic

One RasterizedDB server under Docker Compose, with a named volume, a healthcheck and a restart policy. Start here for a single server on one host, and add to it from the other recipes.

What you get

  • The server on the PostgreSQL protocol (5432) and the native protocol (61170), published on 127.0.0.1.
  • The role rasterized, a superuser, with the password from .env.
  • Data on the volume rasterizeddb_data.
  • restart: unless-stopped, so the server comes back after a crash or a reboot of the Docker host.
  • stop_grace_period: 60s, so docker compose stop and down give the server time to shut down cleanly.
  • A healthcheck: the container reads healthy once the PostgreSQL port accepts connections. Other services can wait for it with depends_on: condition: service_healthy.

Prerequisites

  • Docker Engine with the Compose plugin (docker compose), or Docker Desktop.
  • On x86-64, a CPU with AVX2 (x86-64-v3).
  • psql, or the postgres:17 image, to check the result.

What to edit

  1. Copy .env.example to .env and set RASTERIZEDDB_PG_PASSWORD. A $ in the password has to be written $$ in .env.
  2. Optional: in compose.yaml, change the command line to add server flags (they are added to the image's own), and drop 127.0.0.1: from a port to accept connections from other machines.
sh
cp .env.example .env

The password is used on the first start only, to create the role. To change it later, run ALTER ROLE rasterized PASSWORD 'the-new-password'; while connected.

Run it

sh
docker compose up -d
docker compose ps

docker compose ps shows (healthy) once the server accepts connections. The first check runs ten seconds after the start.

Check that it works

sh
psql "host=127.0.0.1 port=5432 user=rasterized dbname=postgres sslmode=require" \
  -c "CREATE TABLE greetings (id INT PRIMARY KEY, message TEXT)" \
  -c "INSERT INTO greetings VALUES (1, 'hello')" \
  -c "SELECT * FROM greetings"
text
CREATE TABLE
INSERT 0 1
 id | message
----+---------
  1 | hello
(1 row)

Without psql on the host, run it from the postgres:17 image on the project's network, where the server is reachable by its service name:

sh
docker run --rm -it --network rasterizeddb_default postgres:17 \
  psql "host=rasterizeddb port=5432 user=rasterized dbname=postgres sslmode=require"

Read the server's log:

sh
docker compose logs rasterizeddb

The command line sets --log-level warn. Use info for more, or remove the line for the default (error).

Stop and clean up

Stop and start, keeping everything:

sh
docker compose stop
docker compose start

Remove the container and network. The volume, and so the data, stays:

sh
docker compose down

Remove the data as well. This deletes the database for good:

sh
docker compose down -v

Limits

  • The healthcheck proves that the port is open, not that a query succeeds. The image has no SQL client to do more.
  • The healthcheck uses bash, which the alpine tags do not have. With an alpine tag, remove the healthcheck block.
  • Back the volume up before an upgrade: see Backing up the volume and Upgrading.

The files

compose.yaml · Docker ComposeDOWNLOAD ↓
# RasterizedDB with Docker Compose: one server, a named volume, a
# healthcheck and a restart policy. Copy .env.example to .env first.
name: rasterizeddb

services:
  rasterizeddb:
    image: ${RASTERIZEDDB_IMAGE:-milendenev/rasterizeddb:1.1.0}
    environment:
      # The password of the role `rasterized`, set on the first start.
      RASTERIZEDDB_PG_PASSWORD: ${RASTERIZEDDB_PG_PASSWORD:?set RASTERIZEDDB_PG_PASSWORD in .env}
    # Extra server flags, added to the image's own. Remove or extend.
    command: ["--log-level", "warn"]
    ports:
      # 127.0.0.1 keeps the ports on this machine. Drop the address to
      # accept connections from other machines.
      - "127.0.0.1:5432:5432"   # PostgreSQL protocol
      - "127.0.0.1:61170:61170" # native protocol (rasterizeddb_client, Studio)
    volumes:
      - data:/var/lib/rasterizeddb
    restart: unless-stopped
    stop_grace_period: 60s
    healthcheck:
      # The image has bash but no SQL client: this checks that the
      # PostgreSQL port accepts a connection.
      test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/5432"]
      interval: 10s
      timeout: 5s
      retries: 6
      start_period: 30s

volumes:
  data:
.env.example · Environment fileDOWNLOAD ↓
# Copy to .env next to compose.yaml and change the password.

# The password of the role `rasterized`, used on the first start only.
RASTERIZEDDB_PG_PASSWORD=change-me-to-a-long-random-password

# The image and tag. Pin a full version.
RASTERIZEDDB_IMAGE=milendenev/rasterizeddb:1.1.0
✓ page rendered in 147 µs axum + tera + htmx · no other javascript