agentleFS
anderson-c-santosanderson-c-santos/claude-skills-network/skills/docker-swarm/SKILL.md

docker-swarm

Skill1 starsChanged 5 months agoMITView on GitHub

Use this skill for Docker Swarm — stack deployment with docker-compose files, immutable config/secret versioning pattern for rolling updates, service constraints and placement, overlay networks, and Swarm maintenance. Activate for docker stack, docker service, or docker swarm commands.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Manager quorum: always maintain odd number of managers (1, 3, 5).

    line 215

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Docker Swarm

Stack Deployment

# Deploy or update stack
docker stack deploy -c stack.yml mystack --with-registry-auth

# List stacks and services
docker stack ls
docker stack services mystack
docker stack ps mystack              # tasks (containers) per service

# Remove stack
docker stack rm mystack

Compose File for Swarm

version: "3.8"

services:
  app:
    image: registry.local:5000/myapp:1.0.0
    deploy:
      replicas: 2
      placement:
        constraints:
        - node.role == worker
        - node.hostname == prod-server
      update_config:
        parallelism: 1
        delay: 10s
        failure_action: rollback
      restart_policy:
        condition: on-failure
        max_attempts: 3
    ports:
    - target: 3000
      published: 3000
      mode: ingress          # Swarm load-balanced ingress
    networks:
    - mynet
    environment:
    - APP_ENV=production
    configs:
    - source: app-config-v1
      target: /app/config.json
    secrets:
    - source: db-password-v1
      target: /run/secrets/db_password

configs:
  app-config-v1:
    external: true

secrets:
  db-password-v1:
    external: true

networks:
  mynet:
    driver: overlay
    attachable: true

Immutable Config/Secret Versioning Pattern

Problem: Swarm configs and secrets are immutable — you can't update the content. Changing the stack file to reference a new version forces a rolling update.

Pattern — always version with a suffix:

# Create new config version
docker config create app-config-v2 ./config.json

# Update stack file to reference v2
sed -i 's/app-config-v1/app-config-v2/' stack.yml

# Redeploy (rolling update triggered automatically)
docker stack deploy -c stack.yml mystack

# Clean up old version after all tasks updated
docker config rm app-config-v1

Secrets (same pattern):

echo "new-secret-value" | docker secret create db-password-v2 -
# Update stack.yml: db-password-v1 → db-password-v2
docker stack deploy -c stack.yml mystack
docker secret rm db-password-v1

Automation helper:

#!/bin/bash
CONFIG_NAME="app-config"
VERSION=$(date +%Y%m%d%H%M%S)
NEW_NAME="${CONFIG_NAME}-${VERSION}"

docker config create "$NEW_NAME" ./config.json
sed -i "s|${CONFIG_NAME}-[0-9]*|${NEW_NAME}|g" stack.yml
docker stack deploy -c stack.yml mystack
echo "Deployed with $NEW_NAME"

Service Management

# Force update (trigger rolling restart without image change)
docker service update --force mystack_app

# Scale a service
docker service scale mystack_app=4

# Update image
docker service update --image registry.local:5000/myapp:1.1.0 mystack_app

# Rollback a service
docker service rollback mystack_app

# Get service logs
docker service logs mystack_app --tail=100 -f

# Inspect task failures
docker service ps mystack_app --no-trunc   # shows error messages

Placement Constraints

deploy:
  placement:
    constraints:
    - node.role == manager          # only on manager nodes
    - node.role == worker           # only on worker nodes
    - node.hostname == prod-server  # specific host
    - node.labels.gpu == true       # custom node label

Add custom label to node:

docker node update --label-add gpu=true NODE_ID
docker node ls                               # get NODE_ID

Overlay Networks

# Create overlay network manually
docker network create --driver overlay --attachable mynet

# Inspect network
docker network inspect mynet

# Services on same overlay network can reach each other by service name
# e.g., http://mystack_db:5432 from mystack_app

Configs and Secrets Management

# Create
docker config create myconfig ./config.json
echo "secret-value" | docker secret create mypassword -

# List
docker config ls
docker secret ls

# Inspect (content only visible at creation time for secrets)
docker config inspect --pretty myconfig

# Remove (only if not used by any service)
docker config rm myconfig
docker secret rm mypassword

Secret file in container: mounted at /run/secrets/SECRET_NAME. Read via:

with open("/run/secrets/db_password") as f:
    password = f.read().strip()

Swarm Cluster Management

# Initialize swarm
docker swarm init --advertise-addr NODE_IP

# Get join tokens
docker swarm join-token worker    # for worker nodes
docker swarm join-token manager   # for manager nodes (add carefully)

# List nodes
docker node ls

# Remove a node
docker node update --availability drain NODE_ID   # gracefully drain tasks
docker swarm leave --force                         # run on the node itself
docker node rm NODE_ID                             # run on manager

# Promote/demote manager
docker node promote NODE_ID
docker node demote NODE_ID

Manager quorum: always maintain odd number of managers (1, 3, 5). Losing majority = cluster freezes. For homelab: 1 manager is fine; for HA: 3 managers minimum.

Registry Authentication

# Login to private registry
docker login registry.local:5000

# Deploy with registry auth (reads from ~/.docker/config.json)
docker stack deploy -c stack.yml mystack --with-registry-auth

Troubleshooting

# Why is a service not running?
docker service ps mystack_app --no-trunc

# Task inspect (failed task detail)
docker inspect TASK_ID

# Node resource availability
docker node inspect NODE_ID --pretty

# Service didn't update after config change
docker service update --force mystack_app   # force re-pull + restart

# Container won't start (config/secret not found)
docker config ls  # verify config name matches stack.yml exactly

Common mistakes:

ProblemCauseFix
Config update has no effectConfigs are immutableCreate new version, update stack.yml, redeploy
Service stuck at PreparingImage not found in registrydocker pull on node manually, check auth
Overlay network unreachableFirewall blocking VXLAN 4789/udpAllow UDP 4789 between all Swarm nodes
Task constantly failsBad config/secret mountdocker service ps --no-trunc for error message
Port not accessibleSwarm routing mesh only works on published portsVerify mode: ingress and host firewall

Production Checklist

  • Image tags are never latest — use versioned tags for rollback.
  • Configs and secrets follow versioning pattern (never edit in place).
  • update_config.failure_action: rollback on all production services.
  • restart_policy.max_attempts: 3 to avoid infinite crash loops.
  • Deploy node labels for placement; never rely on hostname alone (hostnames change).
  • Overlay networks use attachable: true only if you need manual container attachment.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.