Skip to main content
The repository’s Dockerfile builds the service image and docker-compose.yml runs it next to Postgres. This page takes a fresh clone to a ready testnet facilitator on localhost:8080.
You need Docker with the Compose v2 plugin and git. Node.js and pnpm are not needed on the host: the image builds with its own toolchain.

Published image

Container images are published to the GitHub Container Registry when a version tag vN.N.N is pushed, as ghcr.io/tolgayayci/rail402:<version> and :latest, with /health reporting that version. The latest image is 0.2.1, which serves exact only; later versions of the service run from a source checkout. Without a clone, a testnet facilitator that keeps its state in memory is three commands:
STORE=memory suits trying it out: settlements are not durable and only one replica is safe. For a durable setup, use Postgres as below; in the compose file or your own, the published image can replace rail402:local.

One command

From a clone, with Docker (Compose v2), curl and bash:
The script builds the image, creates a testnet fee sponsor inside it and funds the sponsor with Friendbot, writes TESTNET_RPC_URL, TESTNET_SPONSOR_SECRET and SEARCH_CURSOR_SECRET to .env (git-ignored, mode 600), starts Postgres and the service with the service profile, and waits until http://127.0.0.1:8080/ready passes. It never overwrites an existing .env: run it again and it reuses the file and only starts the stack. The steps below do the same by hand.

The image

The Dockerfile has two stages on node:24.19.0-trixie-slim (Debian, because the embedding runtime needs glibc):
  • build installs pnpm 11.22.0, installs dependencies offline from the lockfile, compiles the service, downloads the pinned embedding model and checks its SHA-256 hashes, and deploys the service with production dependencies only.
  • runtime copies the service to /app and the model to /app/models, runs as the unprivileged node user, listens on port 8080, and runs node dist/main.js. A HEALTHCHECK calls /health every 15 seconds.
The version reported by /health comes from the RAIL402_VERSION build argument, dev by default.

Steps

1

Clone and build

This tags the image rail402:local. To stamp a version, build it directly: docker build --build-arg RAIL402_VERSION=$(git rev-parse --short HEAD) -t rail402:local .
2

Create a sponsor account

The sponsor pays settlement fees and the reserves of the channel accounts. Generate a fresh key with the image you just built, and write the service’s secrets to .env in the repository root (it is git-ignored):
The command prints the sponsor’s public key (G…). Fund it with Friendbot, which gives a new testnet account 10,000 XLM:
The service refuses to report ready while the sponsor holds less than MIN_SPONSOR_BALANCE_XLM (25 XLM by default).
3

Start Postgres and the service

Compose starts Postgres, waits for it to be healthy, then starts the service with DATABASE_URL=postgres://rail402:rail402@postgres:5432/rail402 and the variables in .env. On first start the service applies its database migrations and creates its 8 channel accounts on testnet, paid by the sponsor.
4

Check readiness

/ready answers 503 with the same body until every check passes. /supported lists the sponsor and the channel accounts as signers.
5

Pay through it

From a source checkout, the canonical client run pays a stock seller through your instance with fresh Friendbot-funded accounts and checks the balances:
It prints the settlement transaction and the buyer’s and seller’s USDC balances before and after.

Try the Bazaar locally

The Bazaar lists only resources on public hosts, so a seller on your machine is paid through the hosted facilitator but not listed there (bazaar_resource_unsafe). To watch the whole path on your own instance, from payment to listing to search, let it catalog loopback resources on testnet:
The service then logs DISCOVERY_ALLOW_LOOPBACK: loopback resources are cataloged. It refuses the setting together with pubnet; never enable it on an instance others use. After the settlement, the service requests the resource URL itself to confirm the listing, so localhost has to reach the seller from inside the service. The service container has its own loopback: run the seller and the buyer in its network namespace, from a Node.js 24 shell:
In that shell, follow the seller quickstart with FACILITATOR_URL=http://localhost:8080 (start the seller in the background with node seller.ts &), then the buyer quickstart. The seller logs awaiting_settlement and then awaiting_origin_verification; a few seconds later the listing is published at trust origin_verified, with two entries in its version history, and search finds it:
rail402 seller check judges a resource as the hosted catalog does, so it reports a loopback seller as bazaar_resource_unsafe. Add --discovery-allow-loopback (discoveryAllowLoopback in checkSellerOrigin) to judge it as this instance will.

Configuration for a working self-host

Every other setting has a default. The full list is on the Configuration page. The service validates its configuration at startup and exits with code 78 and one line, a stable startup code and a message naming the variable, when something is missing or malformed:
node dist/check-config.js runs the same checks without starting the service (see Startup checks).

Access, limits and fees

The image takes the same settings as any Rail402 deployment: See Access keys and Configuration for each one.

No dependency on Rail402’s hosted service

A self-hosted image talks to its database and to the Stellar RPC you configure; the upstream @x402/stellar verifier also reads public Horizon for a ledger-time estimate and falls back to 5 s when Horizon cannot be reached. Nothing in it calls a rail402.dev host. apps/rail402/test/image.integration.test.ts runs the image on a Docker network with no route to the internet, every rail402.dev host it could name resolved to 0.0.0.0, its own Postgres, and a relay to a private Stellar network: the preflight exits 78 with the documented code for each missing required setting, and the configured service settles exact and upto, refuses requests without a key (401) or past a limit (429), refuses a token outside TESTNET_ASSETS and a settlement past a key’s sponsor budget, and reports the service fee at /usage. Run it with RAIL402_IMAGE=<tag> and docker compose --profile stellar up -d.

Compose profiles

Every published port (5432, 8000 and 8080) is bound to 127.0.0.1. To expose the service, put a TLS-terminating reverse proxy in front of it and set TRUSTED_PROXY_HOPS. The bundled Postgres keeps its data in the postgres-data volume; for anything beyond a trial, use a managed Postgres with point-in-time recovery (see Operations).

Operate

channels status prints one JSON line per network:
On SIGTERM the service stops accepting requests, lets in-flight settlements finish for up to SHUTDOWN_GRACE_MS (30 s), reconciles once more and exits. Idle connections and requests whose headers or body are still arriving are dropped at once (none has been acted on yet), and a client gets at most 1 s more to take an answer, so only settlements still at work hold the shutdown up. Compose allows 40 seconds (stop_grace_period).

Pubnet

The image can be configured for stellar:pubnet, but pubnet has not been exercised end to end. Its configuration has stricter rules, checked at startup: an https RPC URL, an explicit PUBNET_REQUIRE_API_KEY, an explicit sponsor budget (PUBNET_MAX_SPONSOR_SPEND_XLM_PER_HOUR), explicit fee ceilings and an inclusion floor of at least 200 stroops, explicit PUBNET_ASSETS with a minimum amount per asset, the sponsor’s cold signer (PUBNET_SPONSOR_COLD_SIGNER), and channel accounts that are not created at startup but provisioned by an operator. Run node dist/check-config.js with the same environment before replacing a running container: it exits 78 with the startup error code when the service would refuse the configuration. See Configuration and Operations.