-
Notifications
You must be signed in to change notification settings - Fork 0
Create Stack
Mikhail Konin edited this page Feb 28, 2026
·
1 revision
Step-by-step guide for creating a new application stack.
stacks/my-app/
βββ docker-stack.yml # Docker Compose for Swarm
βββ services.yaml # Service definitions
βββ variables.yaml # Build/deploy variables
βββ externals.yaml # Required secrets
βββ settings.yaml # Stack settings
βββ templates.yaml # Jinja2 config (optional)
βββ templates/ # Jinja2 templates (optional)
β βββ docker-stack.j2
βββ hooks/
βββ pre-deploy.sh # Runs BEFORE deploy
βββ post-deploy.sh # Runs AFTER deploy
swarmcli create
# Select: Stack
# Choose profile, enter stack name
# Wizard creates all files with documenting commentsThen edit the generated files β fill in your services and configuration.
cd /opt/swarmcli/profiles/server-dev/stacks
mkdir -p my-app/hooks
cd my-appEach service needs a type: git (built from source), registry (pre-built image), or none (derived service).
services:
api:
type: git
repo: https://github.com/your-org/api.git
default_branch: develop
build:
context: .
dockerfile: Dockerfile
image: local/api
meta:
group: backend
name: API Service
redis:
type: registry
image: redis:7-alpine
meta:
group: cacheSee Services for type details.
For type: git services, use TAG_* variables (auto-generated from service name, uppercased, hyphens become underscores):
services:
api:
image: local/api:${TAG_API}
ports:
- "8080:8080"
environment:
- TZ=${GLOBAL_TZ}
- LOG_LEVEL=${DEPLOY_LOG_LEVEL}
networks:
- backend
deploy:
replicas: 2
update_config:
parallelism: 1
delay: 10s
redis:
image: redis:7-alpine
networks:
- backend
networks:
backend:
driver: overlaybuild:
NODE_ENV: production
runtime:
env:
LOG_LEVEL: info
API_VERSION: "1.0.0"services_ready_timeout: 45
diagnostics_logs_tail: 30secrets: []If secrets needed:
secrets:
- db_password
- api_keyhooks/pre-deploy.sh:
#!/usr/bin/env bash
set -eo pipefail
echo "Pre-deploy: $STACK"hooks/post-deploy.sh:
#!/usr/bin/env bash
set -eo pipefail
echo "Post-deploy: $STACK"chmod +x hooks/*.shcd /opt/swarmcli
swarmcli check my-app # Validate
swarmcli deploy my-app --dry-run # Preview
swarmcli deploy my-app # Deploy# services.yaml
services:
nginx:
type: registry
image: nginx:alpine
meta:
group: frontend# docker-stack.yml
services:
nginx:
image: nginx:alpine
ports:
- "80:80"# services.yaml
services:
api:
type: git
repo: https://github.com/your-org/api.git
image: local/api
postgres:
type: registry
image: postgres:15Use type: none for services sharing the same image:
# services.yaml
services:
api:
type: git
repo: https://github.com/your-org/backend.git
image: local/backend
worker:
type: none
redis:
type: registry
image: redis:7-alpine# docker-stack.yml
services:
api:
image: local/backend:${TAG_API}
command: ["./app", "serve"]
worker:
image: local/backend:${TAG_API}
command: ["./app", "worker"]
redis:
image: redis:7-alpineFor complex stacks with variable substitution and resource injection:
swarmcli template init my-appSee Jinja2-Templating for details.
- Stack directory created
-
services.yamlwith service definitions -
docker-stack.ymlwith Swarm config -
variables.yamlwith variables -
settings.yamlwith timeouts -
externals.yaml(even if empty) - Hooks executable (
chmod +x) -
swarmcli checkpasses
Next: Deployment-Guide
SwarmCLI Β· Report Issue Β· Contributing Β· MIT License