Docker Swarm Stack Generator
A YAML manifest with replicas, rolling updates, secrets and an overlay network
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Node constraints
One == or != expression per line, for example node.role == worker.
Advanced options
Rate this tool:
Related tools
Other tools you may find usefulDocker Swarm stack generator - a manifest ready for review
The Docker Swarm stack generator creates a stack.yml file for one replicated service. Enter an image with an explicit tag or digest, ports and node constraints, and the tool assembles deploy, a rolling update with rollback, resources, external secrets and an optional overlay network.
The stack uses Compose 3.8 syntax because docker stack deploy still consumes the legacy Compose v3 format. This is not a local docker compose up file: Swarm interprets replicas, placement and the routing mesh across a cluster. For a development environment, start with the Docker Compose generator.
What goes into the generated YAML
| Section | Purpose | Review point |
|---|---|---|
image | Image pulled by every node | the tag cannot be latest; prefer a digest |
replicas | Number of service tasks | CPU and memory reservations must fit the nodes |
placement | Filters nodes by role and labels | labels must exist before deployment |
update_config | Updates one replica at a time | monitors failure and starts rollback |
healthcheck | Requests the /health endpoint | the image must contain wget |
secrets | Mounts files under /run/secrets | external secrets must already exist |
Image tags and a non-root user
docker stack deploy does not build an image from a build field. Build it in CI, push it to a registry, then enter a full reference such as registry.example.com/api:1.4.2. The generator rejects a missing tag, latest, whitespace and attempts to append another YAML line. For immutable releases, replace a tested tag with @sha256:....
A Swarm manifest cannot set the Dockerfile USER instruction. The process inside the image should run under an unprivileged account and copied artifacts should belong to that account. Create a secure image baseline with the Dockerfile generator.
Deploying the stack step by step
- Label every node referenced by constraints, for example
docker node update --label-add env=production worker-1. - Create the secrets named at the end of the YAML. Never commit the source password files.
- Authenticate nodes to a private registry, or pass
--with-registry-authduring deployment. - Save the output as
stack.ymland check indentation in the YAML validator. - Run
docker stack deploy --with-registry-auth -c stack.yml myapp, then inspectdocker stack services myappanddocker service ps myapp_myapp.
Ingress ports, overlay networking and internal services
A published port greater than zero creates long syntax with ingress mode. The routing mesh accepts traffic on every node and forwards it to an available replica. A zero value omits ports completely; there is no misleading expose, because services sharing the overlay can already reach the container port.
The overlay network connects tasks on different hosts. The generator does not make it attachable, so standalone containers cannot join without a reason. In a larger system, separate frontend and backend networks instead of putting every service in one communication domain.
Healthcheck, rolling update and rollback
The probe runs wget against 127.0.0.1 and /health. Change the path if the application uses another endpoint, or disable it for a worker or database. Valid YAML cannot guarantee a valid probe: the binary must exist in the image and the endpoint should not depend on a remote service.
An update starts one new replica at a time, observes it for 30 seconds and enters rollback after the first failure. The start-first order temporarily needs capacity for old and new tasks. Reservations guide scheduling, while limits prevent one container from consuming a whole host.
Secret and placement security
The generator declares secrets as external: true. It never places their values in environment variables, labels or image layers. The application reads the appropriate file from /run/secrets/<name>. To rotate one, create a new versioned secret and update the service because a secret object is immutable.
Every constraint must be a single key == value or key != value expression. The tool quotes each value in YAML and rejects extra instructions. Constraints do not replace capacity monitoring: an overly narrow label set leaves tasks pending. To compare orchestrators, open the Kubernetes Deployment generator.
Frequently asked questions
Why does the generator require an image tag?
Without one, Docker assumes latest, so the same manifest could pull different code tomorrow. An explicit version makes rollback practical; a digest makes the reference immutable.
Will Swarm build an image from my local Dockerfile?
No. docker stack deploy does not perform the build. Build and push the image first so every eligible node can pull it.
Why is a service stuck in pending state?
Usually no active node matches all constraints or has enough free resources for the reservations. Run docker service ps --no-trunc for the scheduler message.
Does a failing healthcheck automatically roll back a release?
During an update, an unhealthy task counts as a failure monitored by update_config. Outside an update, Swarm replaces the unhealthy task under the restart policy.
How do I rotate a password without writing it in YAML?
Create a new secret with a versioned name, change the declaration and deploy again. Remove the old secret only after every replica uses the new one.