Skip to content

Docker: Swarm mode (services & stacks)

10 Docker commands: Swarm mode (services & stacks). Click a command to see what each part does.

Index
10 items
Click a command to see what each part does.

Swarm mode (services & stacks)10

  • docker swarm init --advertise-addr <ip>Turn this host into a swarm manager

    What each part does

    1. docker swarm initcreate a single-node swarm with this host as manager
    2. --advertise-addr <ip>the address other nodes use to reach it
  • docker swarm join-token workerGet the join command for workers

    What each part does

    1. join-token workerprint the docker swarm join command (use manager for extra managers)
  • docker node lsList nodes

    What each part does

    1. docker node lsnodes, status, availability and manager status
  • docker service create --name <service> --replicas 3 -p 80:80 <image>:<tag>Create a replicated service

    What each part does

    1. docker service createa long-running service the swarm keeps alive
    2. --replicas 33 tasks spread over the nodes
    3. -p 80:80publish through the routing mesh on every node
  • docker service ls; docker service ps <service>List services and where their tasks run

    What each part does

    1. docker service lsservices with replicas running/desired
    2. docker service ps <service>each task, its node, state and errors
  • docker service scale <service>=5Scale a service

    What each part does

    1. scale <service>=5set the number of replicas
  • docker service update --image <image>:<new-tag> <service>; docker service rollback <service>Rolling update to a new image, and roll back

    What each part does

    1. service update --imagerolling replace of tasks with the new image
    2. service rollbackgo back to the previous spec
  • docker service logs -f <service>Logs of all tasks of a service

    What each part does

    1. docker service logsaggregated logs from every task
    2. -ffollow
  • docker stack deploy -c compose.yaml <stack>; docker stack rm <stack>Deploy and remove a stack from a compose fileCaution

    What each part does

    1. stack deploy -c compose.yaml <stack>create or update all services in the file
    2. stack rm <stack>remove the stack's services and networks
  • printf '%s' "$VALUE" | docker secret create <name> -Store a secret for services

    What each part does

    1. printf '%s' "$VALUE"the secret value without a trailing newline
    2. docker secret create <name> -store it encrypted in the swarm; services mount it at /run/secrets/<name>

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…