A Docker Swarm stack file builder that generates a docker stack deploy-ready compose
v3.8 file. Each service gets a full deploy block — replicas, placement constraints, a safe
rolling-update policy, restart rules, and resource limits — plus external secret references
and an overlay network tying the cluster together.
How it works
A stack file looks like a compose file but adds a deploy section that only Swarm
interprets. For every service the builder emits replicas, an optional placement.constraints
list, and an update_config using order: start-first with failure_action: rollback so
deploys add capacity before removing it and self-heal on failure. A restart_policy retries
failed tasks, and a resources block sets CPU and memory limits and reservations.
Secrets you list per service are referenced under each service and collected into a top-level
secrets: block marked external: true — meaning you create them once in the cluster with
docker secret create and never store their values in the file. All services join a single
top-level overlay network so they can reach each other by name across nodes.
Tips and notes
- Run
docker stack deployon a manager node. Workers cannot deploy stacks, and the overlay network requires Swarm mode to be active. - Create secrets first:
echo "value" | docker secret create db_password -. Theexternal: truereference will fail to deploy if the secret does not already exist. - Keep
update_config.parallelismat 1 for stateful services so you never take down more than one replica at a time; raise it for stateless services to deploy faster. - Placement constraints are AND-ed together. Use node labels
(
docker node update --label-add tier=app node1) to target specific hardware tiers cleanly.