Repository navigation
Swarm on one node: services, stacks, secrets and configs, so Dokploy runs - #731
Open
masihmoloodian wants to merge 1 commit into
Open
masihmoloodian wants to merge 1 commit into
masihmoloodian wants to merge 1 commit into
Conversation
masihmoloodian
force-pushed
the
feat/swarm
branch
4 times, most recently
from
November 25, 2026 12:54
c601086 to
c52c0e2
Compare
…runs
Every Swarm request answered 404 ("Kiri does not support POST
/services/create yet"), so `docker service`, `docker stack deploy` and
platforms that deploy through Swarm, such as Dokploy, did not work.
Kiri is now a swarm of one node, its leader:
- `swarm init`/`leave`/`update`, `node ls`/`inspect`/`update`, and the
Swarm block of `/info`; before `init`, Docker's "not a swarm manager"
503 on every Swarm endpoint.
- Services and tasks, with the filters the CLI and Traefik send. A task
is an ordinary container, named and labelled as Docker names it, made
through the same create as `docker run`. A thread keeps each service
as its spec says: replicas or global, restart policy, placement
constraints, rolling updates (parallelism, delay, stop-first or
start-first, monitor, failure action) and rollbacks.
- `--driver overlay` networks, which are bridge networks that report
overlay and swarm. A service's name and `tasks.<name>` resolve on
them to its tasks.
- `--publish` in host mode, and in ingress mode, where one running task
takes each port.
- Secrets and configs, mounted read-only at their targets.
- `service logs` and task logs, merged from the tasks' containers.
The state is kept in `swarm.json` beside `networks.json`, readable only
by its owner. Not here: joining other nodes, autolock, job services, and
a virtual IP per service (names resolve to the tasks, as with
`--endpoint-mode dnsrr`).
Refs libracoder#603
masihmoloodian
force-pushed
the
feat/swarm
branch
from
November 28, 2026 06:43
c52c0e2 to
a523e17
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes and why
Every Swarm request answered 404, so
docker service,docker stack deployand platforms that deploy through Swarm failed on Kiri. Dokploy, from #603, is one:Kiri is now a swarm of one node, and that node is the leader. Everything lives in a new module,
crates/kiri/src/daemon/swarm.rs. The rest of the daemon changes only in small hooks: a field onEngine, the route inapi.rs, theSwarmblock of/info, and overlay networks reported asoverlay/swarm.swarm init,leave,update;node ls,inspect,update;info .Swarm. Beforeinit, every Swarm endpoint answers Docker's "This node is not a swarm manager" 503.service create,ls(status=true),ps,inspect,scale,update(versionis checked),rollback(rollback=previous),logs,rm. Filters are the ones the CLI, dockerode and Traefik send, including_up-to-date.<service>.<slot>.<task id>and carrying Docker'scom.docker.swarm.*labels. They are made through the same create asdocker run, so mounts, env, healthchecks and limits are the existing code's.node.role,node.id,node.hostname,node.platform.*,node.labels.*), rolling updates (parallelism, delay, stop-first/start-first, monitor, failure action) and rollbacks, withUpdateStatusas the CLI's progress reads it. A healthcheck counts: a task is running only once healthy.--driver overlay(refused with 403 outside a swarm) is a bridge network that reportsoverlayandswarm. A service's name andtasks.<name>resolve on it to its tasks.--publishin host mode, and in ingress mode, where one running task takes each port. A port with no number given gets one from 30000–32767./run/secrets/<name>or the config's target, withFile.Mode.docker stack deploy/rm,stack ps/services.The swarm is kept in
swarm.jsonnext tonetworks.json, written atomically and readable only by its owner. A daemon restart keeps the swarm and its services.Not here yet, and listed in
docs/features.md:--endpoint-mode dnsrrdocker run --networkon an overlay network that isn't attachableSecrets are files readable only by their owner, not encrypted as in Docker's Raft log.
This is a large change. CONTRIBUTING asks for agreement on an issue before one this size, and #603 hasn't had a maintainer's answer yet. Most of it is one new file, though, and I'm happy to split it into smaller PRs (swarm and nodes, then services, then networks and ports, then secrets and stacks) or to change the approach.
Refs #603
How you tested it
On this branch, with docker CLI 29.8.2 against the Kiri it builds:
Dokploy end to end. I ran its
install.shsteps against Kiri:swarm init, the overlaydokploy-network, two secrets, thedokploy-postgresanddokployservices, and the Traefik container on 80/443. Then, through Dokploy's API, I deployed:nginx:alpine)docker/welcome-to-docker)Both run as Swarm services and answer through Dokploy's Traefik at
hello.localhostandbuilt.localhost. Redeploy (Dokploy sendsForceUpdate + 1), stop and start (scale 0/1) work. So do the commands Dokploy's UI runs inside its container:docker service ps/ls --format,docker node inspect,docker info --format '{{.Swarm.LocalNodeState}}'anddocker service logs --timestamps. A daemon restart keeps it all running.cargo test -p kiri: 673 passed. 14 are new inswarm.rs. Most test the planner as a pure function, without a VM: restart conditions, scale down, an update one task at a time, start-first, a failed update rolling back, an update that isn't done while a slot waits, constraints, ports, version checks, and state that survives a restart.tests/e2e.sh: a new section, "swarm", with 26 checks. They run only when no swarm of the user's own is active, and leave the engine as they found it. The suite, on this branch rebased onto main (f9cd271): 799 passed, 4 failed, 1 skipped. Three of them (default-bridge-no-names,dns-failed-start-gone,disconnect-dns-gone) expect a name that doesn't exist not to resolve. This Mac's DNS answers every name with a 198.18.0.0/15 address, so they fail with or without this change. The fourth,finder-big(50 MB read through the Finder share, which this change does not touch), passed when the Finder checks were run again on their own (16 passed).cargo clippy -p kiri: no new warnings (49 on main, 49 here).Tested on: macOS 27.2.1, Apple M4 Pro, docker CLI 29.8.2. The daemon code is the same on every host, but I haven't run it on Windows or Linux.
Found while testing Dokploy, not in this PR:
docker buildfrom a docker CLI inside a container (Dokploy's CLI 28.5 with buildx 0.39) doesn't put the image in Kiri's store. buildx sees no built-in BuildKit and makes its owndocker-container"default" builder withoutdefault-load, so the result stays in the build cache.docker builduses that default builder whateverbuildx usesays.DOCKER_BUILDKIT=0(Kiri's classic/build) works, so the Dokploy test set it on thedokployservice. This affects any containerized docker CLI, CI runners too: #734.How you found it
AI tools used to write this change:
Checklist
cargo fmt,cargo clippyand the tests pass (no rustfmt config in the repository; the new lines follow the files' style)(daemon code shared by every host; tested on macOS only)