Skip To Content

Deployment

Run Squirix with Docker and Docker Compose.

This repository includes two Dockerfiles and sample docker-compose files for running a small local squirix cluster. Run all commands below from the repository root. Multiline commands use Bash syntax.

Contents:

  • docker/Dockerfile: multi-stage build from repository sources (matches the current checkout)
  • docker/Dockerfile.release: installs squirix-server from the squirix.server.tool NuGet package
  • Squirix.Server.Host: standalone server executable that starts a node and waits
  • docker/docker-compose.yml: three-node RF=3 HA example (sources image)
  • docker/docker-compose.release.yml: three-node RF=3 example (release image, local package drop; secrets via .env)
  • docker/.env.example: template for release compose (copy to .env for local testing only)
  • docker/node-a/Squirix.settings.json
  • docker/node-b/Squirix.settings.json
  • docker/node-c/Squirix.settings.json

Build (from sources)

docker compose -f docker/docker-compose.yml build

To build the source image directly:

docker build -f docker/Dockerfile -t squirix-server .

Build (release — from NuGet tool)

Published releases (nuget.org). Image tag is arbitrary; the Dockerfile SQUIRIX_VERSION ARG defaults to the published package version (override with --build-arg when needed):

docker build -f docker/Dockerfile.release -t squirix-server:release .

Verify a not-yet-published tool package locally. Packing from source requires the SDK selected by global.json. The version below matches the current SquirixPackageVersion; if you change that property, update the build argument to the same version:

dotnet clean src/squirix.server.host/Squirix.Server.Host.csproj -c Release
dotnet pack src/squirix.server.host/Squirix.Server.Host.csproj -c Release -p:SquirixPackAllFrameworks=true -o docker/nuget-packages
docker build -f docker/Dockerfile.release -t squirix-server:local \
  --build-arg LOCAL_PACKAGES=true \
  --build-arg SQUIRIX_VERSION=0.2.0-preview.1 .

Or use the release compose file (expects packed .nupkg files in docker/nuget-packages/). Its build arguments pin SQUIRIX_VERSION separately; keep that value aligned with the package you packed. Runtime JWT settings and the mTLS PFX password are required from the environment. Copy docker/.env.example to docker/.env for local testing:

The images still contain development HTTPS and mTLS private keys. Loading values from .env does not replace those certificates or make the image suitable for production. Changing the PFX password variable alone cannot change the password of the bundled PFX.

dotnet clean src/squirix.server.host/Squirix.Server.Host.csproj -c Release
dotnet pack src/squirix.server.host/Squirix.Server.Host.csproj -c Release -o docker/nuget-packages
cp docker/.env.example docker/.env
docker compose -f docker/docker-compose.release.yml build

Run

Development only. Compose files and docker run snippets below use public test JWT and mTLS secrets. They are fine on a local machine; copying them unchanged into staging or production lets anyone who knows the fixtures mint valid tokens. See Security and Generate per-environment secrets.

Three-node RF=3 HA cluster (sets sample JWT env vars for all nodes; containers run with Production hosting environment):

docker compose -f docker/docker-compose.yml up -d

Release-image three-node RF=3 cluster (requires docker/.env — copy from .env.example for local testing):

cp docker/.env.example docker/.env
docker compose -f docker/docker-compose.release.yml up -d

For a single local development node (ephemeral, in-memory), build the source image and run it as shown below. To use the release image, substitute squirix-server:release for squirix-server.

docker run --rm \
  -p 5000:5000 \
  -e SQUIRIX_JWT_SIGNING_KEY=ZGV2LXNxdWlyaXgtZG9ja2VyLWp3dC1rZXkhISEhISE= \
  -e SQUIRIX_JWT_ISSUER=https://squirix.docker.dev \
  -e SQUIRIX_JWT_AUDIENCE=squirix \
  squirix-server run --urls https://0.0.0.0:5000

Durable single node with a named Docker volume mounted at /data:

docker run --rm \
  -p 5000:5000 \
  -v squirix-data:/data \
  -e SQUIRIX_JWT_SIGNING_KEY=ZGV2LXNxdWlyaXgtZG9ja2VyLWp3dC1rZXkhISEhISE= \
  -e SQUIRIX_JWT_ISSUER=https://squirix.docker.dev \
  -e SQUIRIX_JWT_AUDIENCE=squirix \
  squirix-server run --urls https://0.0.0.0:5000 --persist --data-dir /data

Port 5000 carries the binary cache protocol over TLS. Port 5002 serves management HTTP/1.1 over TLS. For local management access with docker run, add -p 127.0.0.1:5002:5002 to the command.

Endpoints (three-node RF=3 docker compose example):

  • Node A binary TLS: https://localhost:5001 (host port maps to container 5000)
  • Node B HTTPS: https://localhost:5002
  • Node C HTTPS: https://localhost:5003
  • Management HTTPS on the host uses https://localhost:5201, https://localhost:5202 and https://localhost:5203 respectively.
  • The container binds client traffic on port 5000 from the mounted Squirix.settings.json and management traffic on 5002.

Mounted settings use Docker DNS hostnames for cluster traffic (https://squirix-node-a:5000, https://squirix-node-b:5000, https://squirix-node-c:5000). Host applications use the published ports (5001, 5002, 5003) instead. Each node's Cluster.Uri must match its local peer entry (see configuration.md).

Peers[].Uri always carries the primary listener origin (port 5000 in the samples). The internode mTLS binary peer endpoint is derived from that origin by swapping in SQUIRIX_CLUSTER_MTLS_INTERNAL_PORT (5100): keep each local peer entry aligned with its configured peer URI and never enter port 5100 in Peers[].Uri — fingerprint and peer matching expect the primary origin.

Replica factors

  • RF=1 is a single copy with single-owner routing and no replication.
  • RF=2 is a synchronous mirror only: writes require both replicas (majority is two), so losing either member stops RF=2 writes and no replacement is elected. Use RF=2 for mirroring, not for availability.
  • The HA demo uses RF=3: three nodes with persistence and mTLS keep committing writes on the remaining majority while one follower is down. The example turns on automatic failover and quorum reads, so when a node that leads a group goes down, the remaining two elect a new leader. Both switches are part of the topology fingerprint: remove the volumes of an earlier run (docker compose -f docker/docker-compose.yml down -v; this deletes the sample cluster data) before starting with changed settings. All three nodes must run the same homogeneous build; mixed package versions fail readiness through the topology fingerprint.
  • RF>1 additionally requires the explicit replication opt-in (Squirix:Cluster:ReplicationEnabled or --enable-replication); without it RF>1 nodes refuse startup. The compose settings set the opt-in.

HTTPS in containers

Both images bundle a self-signed development PFX at /https/squirix.pfx with an empty export password. The source image certificate has SANs for localhost, 127.0.0.1, and squirix-node-a, squirix-node-b, squirix-node-c. The release image includes the squirix-node-*-release names. The server loads the PFX from SQUIRIX_TLS_CERTIFICATE_PATH.

For a real deployment, configure your own trusted certificate for the primary HTTPS listener as well as separate internode mTLS material. The bundled primary certificate does not cover arbitrary deployment hostnames.

For local development probes, use curl -k from the host. To connect with the .NET client from the host, trust the container's exported public HTTPS certificate on the client machine. The public client API uses normal TLS validation.

Check health from the host.

curl -k https://localhost:5201/health

To enable the scrape, set Squirix:PrometheusMetrics:enabled to true in the mounted node settings and add --metrics to that node's Compose command before starting it.

command: ["run", "--persist", "--data-dir", "/data", "--metrics"]
curl -k -H "Authorization: Bearer <jwt>" https://localhost:5201/metrics

Remote scrapes (including host → published container port) require authentication with a valid JWT bearer token. An unauthenticated remote request receives 401; disabling JWT does not make remote scrapes anonymous.

Cache clients must supply JWT via options.BearerTokenProvider for connection authentication and trust the server's HTTPS certificate. The public client does not expose a certificate-validation override. For a complete local example, use the Docker client: it generates a short-lived JWT and trusts the exact server certificate inside an isolated client container, without changing the host trust store. curl -k above is only for local diagnostic probes, not the client trust setup.

See health routes and the metrics endpoint.

Multi-node internode mTLS

The three-node RF=3 compose layouts configure external JWT auth and a primary HTTPS listener (container port 5000). When Peers[] lists remote nodes, Squirix also requires cluster mTLS environment variables. The sample compose files set SQUIRIX_CLUSTER_MTLS_* to development-only certificates baked into the image at /mtls/ (CN matches each node's Cluster.NodeId: A, B, and C in the mounted settings). Squirix does not generate production certificates.

Example additions per service (adjust paths to match your image layout):

environment:
  SQUIRIX_CLUSTER_MTLS_CA_PATH: /mtls/cluster-ca.crt
  SQUIRIX_CLUSTER_MTLS_CERT_PFX_PATH: /mtls/node.pfx
  SQUIRIX_CLUSTER_MTLS_CERT_PFX_PASSWORD: dev-mtls
  SQUIRIX_CLUSTER_MTLS_INTERNAL_PORT: "5100"
volumes:
  - ./mtls/node-a:/mtls:ro

Use the same internal port number on every node (here 5100). It must differ from the primary listener port (5000 in the sample settings). Peers connect to https://<service-host>:5100 on the Docker network. Generate dev certificates with OpenSSL as described in security/internode-mtls.md.

Trust only the PEM cluster CA configured at SQUIRIX_CLUSTER_MTLS_CA_PATH and ensure each mounted node certificate CN matches that container's Cluster.NodeId; do not add ad hoc certificate validation overrides.

Security

Do not deploy Docker examples unchanged to production. docker-compose.yml and single-container docker run snippets embed predictable JWT signing keys and reference development-only mTLS material baked into images at /mtls/. Anyone with repository access can forge JWTs against those keys.

  • Non-loopback listen URLs require JWT settings at startup. The compose examples use a fixed dev signing key for local testing only — see security/jwt-signing-keys.md.
  • For local verification with docker-compose.release.yml, copy docker/.env.example to docker/.env and keep it out of version control. The supplied PFX password matches the development certificates bundled in the release image. To use your own certificates, mount the matching CA and node PFX files and set SQUIRIX_CLUSTER_MTLS_CERT_PFX_PASSWORD to the password for those files.
  • Multi-node clusters require cluster mTLS material in addition to JWT. See security/internode-mtls.md.
  • For production, prefer OIDC/JWKS (SQUIRIX_JWT_AUTHORITY) over symmetric SQUIRIX_JWT_SIGNING_KEY, mount your own cluster CA and node certificates, and store secrets in a secret manager — not in compose files or images.
  • /health, /health/live, and /health/ready stay anonymous. /metrics and /health/ready/details follow the same auth rules as cache routes for remote clients; host → published port counts as remote inside the container. See configuration.md and diagnostics.md.

Generate per-environment secrets

Use distinct JWT and mTLS material per environment (dev, staging, production). Never reuse the Docker dev fixtures.

Symmetric JWT signing key

Follow Generate a per-environment symmetric key for the generation command and the JWT settings required by each node.

Cluster mTLS certificates

Generate a private cluster CA and per-node PKCS#12 files with OpenSSL. Each certificate CN must match that node's Cluster.NodeId. Full walkthrough: security/internode-mtls.md#generate-a-local-test-ca-and-node-certificates-openssl.

Mount the CA and node PFX (or PEM pair) into containers or hosts and point SQUIRIX_CLUSTER_MTLS_* at those paths. Use a strong, unique PFX password per environment.

Persistence

The docker compose examples mount a named Docker volume at /data and start each node with run --persist --data-dir /data. Single-container snippets in getting-started.md default to ephemeral mode unless you add --persist and a data volume as shown above.

The compose layout is for local testing, not a production deployment template.

Before adapting it for a real environment, read: