Runners
Runners is a self-hosted control plane for Docker applications. I use it to deploy apps across Linux machines and manage them from one dashboard.
Live dashboard: runners.hetp.dev
The system at a glance
The control plane decides what should run and where. An agent runs on each Linux host, applies the work assigned to that host, and reports what is actually happening.
Control plane
Chooses and coordinates work
Health
Metrics
authenticated WebSocket
Agent
Runs work on one Linux host
Control plane: making the decisions
The control plane receives Compose definitions and desired replica counts, stores configuration, and chooses placements using the fleet’s reported capacity, region constraints, and current inventory.
- ValidateCheck the app definition and requested changes
- CommitConfirm desired configuration in D1
- ReconcileCompare desired state with agent reports
- Issue plansRelease work under current leadership
- API and configuration
- Validate changes and confirm configuration commits before acknowledging them.
- Scheduling
- Choose eligible hosts, reconcile desired copies with actual inventory, and coordinate moves and recovery.
- Leadership
- The official
etcd/rafthelper handles elections and membership. Quorum-confirmedReadIndexchecks guard work and plan release. - Public addresses
- Manage the app’s Cloudflare DNS and tunnel definitions. The agents operate the local connectors.
A recursive control plane
Runners can deploy its own controller replicas as an ordinary app. The control plane schedules those containers through the same agents that run my other applications, so the system manages part of its own infrastructure.
Host-specific plans
Agent fleet
Inventory reports and controller peer traffic close the loop.
The elected controller above is one of the cluster’s controller processes, shown in its scheduling role and its workload role.
The controller app uses ordinary readiness checks and moves. Its /readyz waits for voter admission and completion of any joint membership change. A replacement starts with a fresh Raft identity, joins as a learner, catches up, and replaces its predecessor through joint consensus.
CP_NODE_ID_OFFSET maps app replica numbers to logical controller slots when fleet-hosted and external peers share a cluster. x-runner.spread-tags: true prefers different server groups when eligible capacity allows.
etcd Raft and scheduling authority
Each controller pairs a Rust process with a supervised Go helper using the official go.etcd.io/raft/v3 library. The helper handles elections, replication, and membership; D1 remains the durable configuration store. Runners uses the Raft library without running an etcd database server.
Connected group of 4
Can elect a leader and confirm quorum
Isolated group of 3
Cannot authorize new scheduling work
Existing approved workloads continue running on agents on either side.
Mutual exclusion here means that only the quorum-confirmed leader may issue new plans. ReadIndex checks guard work and plan release; a stale leader’s local “leader” flag is insufficient. Without quorum, scheduling pauses.
Calls already sent to D1 or Cloudflare can finish after leadership changes. Configuration revisions guard commits, and the current primary reconciles routing. Raft authority does not cancel an external request already in flight.
Agent: doing the work on one host
An agent connects outward to the controller. It receives a host-specific plan rather than independently choosing the fleet’s replica count or placements.
- ReceiveAccept the approved plan for this host
- RunBuild or start the assigned Compose projects
- ObserveProbe readiness and collect local metrics
- ReportSend inventory, health, and results back
- Workload execution
- Build images when needed and apply the assigned Docker Compose projects, versions, and local changes.
- Local observation
- Report container inventory, app readiness, and host and replica resource metrics. The native agent uses the Docker API for observations and the Docker CLI for workload changes.
- Local networking
- Maintain the host proxy and tunnel connectors. A shared app connector is active only while a local app copy is healthy and ready.
- Continuity
- Keep approved plans and recovery inventory locally. Existing authorized workloads can keep running while the controller is unreachable.
Placement and exclusion
The least busy host is useful only if it is eligible. Region rules, health, host lifecycle, Compose conflicts, and capacity all narrow the candidate set before the scheduler ranks it.
- RegionKeep the replica in its assigned region
- SafetySkip leaving, quarantined, or conflicting hosts
- CapacityCheck host limits, stacking, and startup work
- PreferencePrefer distinct hosts, tag diversity, and room
- Hard constraints
- Keep each replica in its configured region. Skip draining, departing, quarantined, or already-due hosts and hosts with conflicting ports or container names.
- Replica separation
allowStackingdefaults tofalse: copies of an app require distinct eligible hosts. Opting in permits compatible copies to share a host; host and region constraints still apply.- Failure exclusion
- After a host-specific failure triggers recovery, that app avoids the host for six hours. If the same version fails on two hosts, Runners treats it as an app-level problem and stops that relocation heuristic.
- Preferences
- Prefer sufficient remaining host lifetime, room, and fewer existing placements. Optional tag spreading is best effort; a required region is strict. If no eligible capacity exists, the replica waits.
Balance useful work, avoid churn
The balancer handles sustained hot hosts, separates doubled-up copies when capacity returns, and moves settled workloads to reduce fleet pressure. Pressure is max(CPU %, RAM %), relative to each host’s capacity. The predicted cost of an app is converted to the destination’s capacity before admission.
Before
After moving one copy A → B
One copy uses 15 percentage points of CPU and 5 of RAM here. Predicted peak pressure falls from 70% to 55%.
A routine load move needs a pressure gap of at least 10 percentage points and a predicted peak-pressure improvement of at least 0.5 points. The destination must also retain a 10-point startup reserve below the 70% CPU and 80% RAM admission thresholds.
- Move safely
- Start the replacement first and retire the old copy only after readiness succeeds. If the replacement fails or times out, cancel the move and keep the working copy.
- Exclude busy work
- Routine balancing skips unsettled versions and hosts doing conflicting startup work. Only one routine move per app runs at a time; independent apps on disjoint hosts can move concurrently.
- Let readings settle
- Wait at least five minutes between an app’s routine moves after completion or cancellation, pace hosts separately, and allow three minutes for startup metrics to settle. Repeated hot-move thrashing pauses that app’s routine moves.
- Recover separately
- Confirmed failures bypass the routine balancing switch, pauses, and pacing. Eligibility and placement constraints still apply. Turning off routine balancing does not disable failure recovery.
Where an application request goes
The control plane handles management. Application requests travel through Cloudflare to a host’s local proxy and app container.
- VisitorRequests an app’s global URL
- CloudflareUses the app’s shared tunnel
- Host proxySelects a ready local replica
- ContainerServes the application request
The controller is outside this request path. Existing apps can keep serving during a controller outage; new placement decisions wait for an authoritative controller.
Where state lives
| Location | What it holds | Lifetime |
|---|---|---|
| D1 | Desired app definitions, versions, and configuration | Durable |
| Controller memory | Runtime reports, metrics, and Raft state | Temporary; members rejoin a surviving quorum |
| Agent host storage | Agent identity, approved plans, inventory, and signed recovery receipts | Preserved locally across agent restarts |
| App volumes | The application’s files and local data | Remain on their host |
Raft state is intentionally volatile in this design. Restarted members can rejoin a surviving quorum; loss of the entire quorum’s memory requires an explicit new-generation bootstrap.
What happens when something disappears
- Host missingAgent reports stop arriving
- RecheckApply liveness and recovery checks
- ReassignPlan a replacement on an eligible host
- Become readyA healthy connector serves the same app URL
- Controller unavailable
- Agents keep their approved workloads and healthy connectors. A surviving Raft quorum can elect a leader; without quorum, scheduling pauses.
- Agent host lost
- The controller uses liveness checks and inventory to plan replacement copies on eligible hosts. Agents start those copies and report readiness.
- Local app unready
- The agent withdraws that app connector. Other ready connectors can serve new requests through the same global hostname.
Reassigning a replica does not copy its local volumes. Applications that need shared state across hosts provide their own shared storage or replication.
A small configuration example
This requests three copies of a simple web server. The control plane turns the desired state into assignments; each agent applies only its own assignment.
x-runner:
port: 8080
replicas: 3
ready: /
services:
web:
image: nginx:alpine
ports:
- "8080:80"
x-runner.replicas sets the desired copy count. x-runner.ready identifies the readiness path used to check whether a copy can serve requests.