Docs pages

Status: accepted 2026-11-27, after security approval in step 15 of plan 0004 (systems reviewed every M3a step) · Date: 2026-11-21 (proposed) · 2026-11-27 (accepted)

Context. M3a is the first milestone that changes Docker state: it pulls images, creates, starts, stops and removes containers, follows Docker events, and reloads the embedded Caddy with app routes. Plan 0002 reserved an ADR for the Docker client and required a versioned op protocol between the control plane and the agent, with size caps and agent output treated as untrusted. M1 built a small typed client (internal/agent/dockerapi) with per-call deadlines and API negotiation (Engine 25+, API 1.44–1.52), and an op table in which the zero value is local-only (ADR 0009). Remote agents are logs-only until Phase 2 (Q1).

Decision.

  1. Keep the hand-rolled, typed Docker client. No Docker SDK module: it would add a large dependency tree, package init work in every mode (S4), and API churn we don't use. Every endpoint is a typed method with a fixed path; every request goes through call (a per-call deadline) or stream (bounded by its context, with a header deadline). Request bodies are Go types that contain only the fields ServerDock is allowed to set, and the final create body passes a default-deny check down to every leaf, in the control plane and again in the agent on the exact bytes sent to Docker. Docker's JSON lines are read with a 64 KiB per-line cap.
  2. Ownership by label, enforced in the agent. Every container ServerDock creates carries serverdock.managed, serverdock.instance (a random id per data directory, set by the agent itself), serverdock.project, serverdock.service, serverdock.deploy and serverdock.attempt, runs a pinned image id, and is named sd-<project>-<service>-d<deploy>-a<attempt> with ids that are never reused. The agent stops, restarts or removes only containers with its own instance label, addressed by a full id it inspected. Images that carry any serverdock.* label are refused.
  3. One app network per install with static addresses. A bridge network named after the install id, created with a subnet ServerDock chose, labelled, with inter-container traffic disabled in M3a. Every container gets a static IPv4 recorded with its deploy, so an upstream never moves to another container after a container or daemon restart. ServerDock publishes no host ports for apps; Caddy is the only entry point.
  4. Op protocol v1. One yamux stream per op. The hub writes one request line (at most 64 KiB) {"v":1,"op":…,"args":…}; the agent answers with progress or event lines (at most 1 KiB each) and exactly one result line (at most the op's limit). Both sides refuse trailing bytes and unknown fields. The hub enforces per-op limits on line size, line count and total bytes, and cleans every string that came from Docker, a registry, an image or a container. A violation fails the op and closes the stream. A hello op (read-only, allowed on remote sessions, result at most 256 bytes) carries the protocol version; an agent that does not know it is treated as v0 (logs only). The v0 logs op is unchanged apart from an optional follow that is never sent to a v0 agent. hello is frozen forever: its envelope is always "v":1, its args {"hub_max_v"} and its result {"v","agent"}, whatever version a session negotiates, so a later v2 hub and a v1 agent can still negotiate; other ops carry the session's negotiated version and the agent accepts 1 <= v <= its maximum. Objects are decoded with exact key matching and no duplicate keys (encoding/json alone matches case-insensitively and keeps the last duplicate); the step-5 create-body policy must use the same rule. Event lines are exempt from the 4 MiB per-op cap (each is at most 1 KiB and events is local-only). The in-process local agent is never sent a hello (it is this binary). Text the hub stores or shows is cleaned; op payloads stay raw until the op's typed decoder cleans them.
  5. All new ops are local-only, on both sides. The hub refuses them to any session other than the in-process local agent, and serverdock agent (remote mode) does not serve them. The remote allowlist is hello and logs; the negotiated version never widens it.
  6. The control plane owns the events reconnect. It keeps one events op open on the local session (no op timeout), reconnects with a 1 s → 30 s jittered back-off while the stream is down, and on every (re)connect opens the stream first, then lists ServerDock's containers and re-inspects those with events buffered during the list.
  7. The commit is authoritative after a crash. A deploy interrupted by a restart after it set the service's active deploy is finished (the old version is removed), not rolled back; an uncommitted one is marked failed and its containers removed. The boot pass changes only database state; one resync rule set, run after every successful events connection, does all container clean-up. This amends plan 0002's M3a interrupt rule.

Consequences.

  • No new Go dependency; later milestones add endpoints (networks and volumes in M3b, image load in M5) under the same rules.
  • A control-plane bug cannot delete containers that ServerDock did not create, two installs on one Docker host don't interfere, and a new service can never adopt an old service's container.
  • ServerDock must reach the app network: it runs on the host or with host networking until the install shape (Q4) decides the container form. The app subnet is chosen at first start and not changed later.
  • The per-op limits are part of the protocol; raising one is a protocol change reviewed by security.
  • Idle cost: one events stream (one Docker connection and two goroutines); no timers of ours while the stream is up.

Addendum A (2026-11-29, plan 0005 step 2): networks, volumes and registry credentials for M3b

Accepted 2026-11-29, after security and systems approved plan 0005 step 2 (plan 0005 Revision 3). Decisions 1, 2 and 4 to 7 stand. Step 2 adds only client methods; the ops that use them come in step 3.

Decision.

  1. Decision 3 gains "plus one internal network per project for service DNS, joined at create time". Each project gets one more bridge network, serverdock-<install id[:8]>-p<project id>, with Internal: true (no outside route, no NAT), its own /25 inside 10.250.0.0/16 and the labels serverdock.managed, serverdock.instance and serverdock.project. A container joins it in the create call itself, as a second endpoint carrying one alias, its service name (the Engine accepts several endpoints at create from API 1.44, our minimum). It stays on the app network too, with its static address. Joining at create time, not after the health gate, is what lets a new version reach db by name while it is checked (plan 0005, Revision 1, B1). The cost is stated in the plan: during a blue-green deploy the name can answer from the new version before the old one stops. The client refuses (ErrNetworkSettings) any existing app or project network whose gateway_mode_ipv4 or _ipv6 is anything other than absent or nat: nat-unprotected would bring back direct routing to unpublished ports.
  2. New ops, all LocalOnly and v1, with the rules of decision 4 (step 3 builds them): volume_ensure, volume_remove, project_network_ensure and network_remove.
    • Volumes are bound to their service id. A volume is named sd-<install id[:8]>-s<service id>-<name>, uses the local driver with no options, and carries serverdock.managed, serverdock.instance and serverdock.service. volume_ensure refuses a volume that exists with another driver, any option, or another instance or service id. volume_remove acts only on a volume with our instance label and a serverdock.service equal to the service argument, is never forced, and reports "in use" as a conflict. A container's create check ties the volume's s<id> to the container's own serverdock.service label.
    • Project networks are created and removed only by name with our labels; network_remove removes only our labelled project networks, never forced, and goes by the full id after an inspect (Docker also matches id prefixes).
  3. Registry credentials travel in one op argument and are never stored on the host. image_pull gains an optional auth (at most 4 KiB, base64url) that the agent puts in the X-Registry-Auth header of that one pull request. It is never in the URL or the body, never logged, never in a result, and it is removed by value (the header, its decoded JSON and the password inside) from every error text. There is no docker login and no credential helper, so nothing is left in a Docker config file; the next pull sends a credential again, or none.
  4. CreateSpec stays a typed whitelist. It gains Env, HostConfig.Mounts (volume and bind, rprivate bind propagation only), Memory, MemorySwap, NanoCpus, SecurityOpt and the Aliases of an endpoint, and nothing else. A spec that does not use them marshals byte for byte as in M3a. The default-deny create check (step 4) still refuses every field it does not list. Env values of 4 bytes or more never appear in a create error, and none appears in a log line or a result; secrets are at least 8 bytes by input rule.

Consequences.

  • No new Go dependency. The Engine endpoints used are POST /volumes/create, GET and DELETE /volumes/{name}, DELETE /networks/{id} and the existing network, image and container calls.
  • A project's services can reach each other on any port. Services of different projects share no network that allows container-to-container traffic (the app network keeps enable_icc=false). Recorded on Docker 29.10.0 (plan 0005 step 2): a container on an internal network can open a TCP connection to a host listener bound to all addresses, through the network's gateway address, and has no default route, so it cannot reach an outside address. That is no host reach beyond what B10 already accepts for the app network's gateway. The real risk it names is third-party host listeners on 0.0.0.0, such as a Docker TCP API, which any container of any project can then reach. Projects are isolated from each other and from the outside, not from the host. Also recorded: project A's container could not reach project B's container at either of B's addresses.
  • On a host whose resolv.conf has a search domain, a bare service name on an internal network can fail (Docker's resolver has no upstream there and answers the search-qualified name with SERVFAIL; --dns-search . avoids it). The step 9 design must not assume a bare name resolves.
  • A new network is created with the nat gateway mode set explicitly on API 1.48 and later, so a daemon-wide default-network-opts cannot give it another gateway mode. The refusal of any other mode is short and points to the recovery steps in docs/architecture.md#gateway-mode-recovery.
  • Network options are default-deny, on the app network and on project networks (plan 0005 step 3). Only the gateway modes, enable_icc, enable_ipv4, enable_ipv6 and a com.docker.network.driver.mtu of 68 to 65535 are allowed. Any other option (a daemon-wide default-network-opts entry, or one set by hand) refuses the network with a short message that points to docs/architecture.md#network-option-recovery. So an option in default-network-opts can make a fresh install refuse its network; to keep recovery short, a network that the same call has just created is removed again (best effort, never forced) when its check fails, and the recovery is then to fix daemon.json and deploy again. A network that already existed is never changed or removed by ServerDock.
  • A network cannot be removed or recreated under a stopped container: after the network is recreated under the same name, starting that container fails (its endpoint names the old network id). Step 9 recreates the container, not only the network.
  • Docker clears State.OOMKilled when a container restarts, so an OOM kill is recorded from the oom event and never recovered from inspect.
  • A stopped container keeps its endpoints, address and alias on both networks, so a stop-first restore of the old version keeps its project name.
  • The ownership rules grow with the resources: a volume or project network that lacks our labels is never touched, and a volume's service binding is checked in the agent, not trusted from the hub.