Docker SWARM 备忘单

Docker Swarm 模式速查表

Docker Swarm Mode is Docker’s native clustering and orchestration solution. It allows you to manage a group of Docker nodes as a single virtual system, enabling high availability, load balancing, and simplified deployment of containerized applications.

Key features:

  • Built-in orchestration
  • Declarative service model
  • Rolling updates
  • Auto-scaling and self-healing
  • Secure node communication via TLS

📌 Swarm Initialization

  • Initialize Swarm

    docker swarm init 
  • Join Swarm (on worker/manager node)

    docker swarm join-token worker 
  • Leave Swarm

    docker swarm leave 
  • Force Leave (on manager)

    docker swarm leave --force 

👥 Node Management

  • List nodes

    docker node ls 
  • Promote node to manager

    docker node promote <node-name> 
  • Demote node to worker

    docker node demote <node-name> 
  • Inspect node

    docker node inspect <node-name> --pretty 
  • Drain node (prevent scheduling)

    docker node update --availability drain <node-name> 
  • Activate node

    docker node update --availability active <node-name> 

🧠 Manager Nodes

Manager nodes are responsible for:

  • Orchestrating tasks and services
  • Maintaining cluster state
  • Handling API requests

You can have multiple managers for high availability, but only one is the leader at any time.

  • Check manager status

    docker node ls 
  • View Raft consensus info

    docker swarm inspect 

📦 Service Management

  • Create service

    docker service create --name <service-name> <image> 
  • Create service with replicas

    docker service create --name <service-name> --replicas <n> <image> 
  • List services

    docker service ls 
  • Inspect service

    docker service inspect <service-name> --pretty 
  • Scale service

    docker service scale <service-name>=<n> 
  • Update service

    docker service update --image <new-image> <service-name> 
  • Remove service

    docker service rm <service-name> 

🔁 Replicas

Replicas define how many instances of a service should run across the swarm.

  • Set replicas when creating a service

    docker service create --replicas 5 --name myapp myimage 
  • Scale replicas

    docker service scale myapp=10 

Swarm automatically distributes replicas across available nodes and restarts them if they fail.

🐝 Task & Container Management

  • List tasks of a service

    docker service ps <service-name> 
  • List all tasks

    docker node ps <node-name> 
  • List containers

    docker container ls 
  • Inspect container

    docker container inspect <container-id> 

🌐 Networking

🧠 What Is an Overlay Network?

An overlay network is a virtual network that spans across multiple Docker hosts. It allows containers running on different nodes

Commands

  • Create overlay network

    docker network create --driver overlay <network-name> 
  • List networks

    docker network ls 
  • Attach service to network

    docker service create --name <service-name> --network <network-name> <image> 

🛠 Useful Flags

FlagDescription
--replicasNumber of service instances
--publishPort mapping (<host>:<container>)
--mountVolume mounting
--constraintNode placement rules
--update-delayDelay between updates
--limit-cpu / --limit-memoryResource limits

📄 Example: Create a Web Service

docker service create \ --name web \ --replicas 3 \ --publish 80:80 \ --network webnet \ nginx 

相关工具 (20)

chmod 命令速查表
Linux 权限变更速查表
常用正则表达式备忘单
常用正则表达式模式备忘单。
CSS选择器备忘单
CSS选择器语法备忘单。
Docker Compose 备忘单
Docker Compose 格式备忘单
Docker备忘单
Docker命令备忘单。
Docker SWARM 备忘单
Docker Swarm 模式速查表
Dockerfile 备忘单
Dockerfile 语法和构建备忘单
Git语义提交备忘单
使用语义前缀提交Git的备忘单
JQ备忘单
JQ命令备忘单
JSONPath语法备忘单
JSONPath语法备忘单
Markdown备忘单
Markdown备忘单
Nano备忘单
Nano编辑器备忘单
正则表达式备忘单
JavaScript正则表达式备忘单
Sed 备忘单
sed unix 命令速查表
XPath语法备忘单
XPath语法备忘单
ZPool 备忘单
OpenZFS/ZPool 使用命令和信息
Docker Compose格式转换器
在V1、2.x、3.x或CommonSpec之间转换Docker Compose文件,可扩展端口/卷语法。
Docker Compose到Docker运行转换器
将Docker Compose文件转换为docker run命令!
Docker Compose 到 .env 文件
从现有的 Docker Compose 文件中提取 .env 文件
Docker Compose到Kubernetes
Docker Compose转换为Kubernetes清单。
留言区
昵称
邮箱
网址
0/1000
  • OωO
  • |´・ω・)ノ
  • ヾ(≧∇≦*)ゝ
  • (☆ω☆)
  • (╯‵□′)╯︵┴─┴
  •  ̄﹃ ̄
  • (/ω\)
  • ∠( ᐛ 」∠)_
  • (๑•̀ㅁ•́ฅ)
  • →_→
  • ୧(๑•̀⌄•́๑)૭
  • ٩(ˊᗜˋ*)و
  • (ノ°ο°)ノ
  • (´இ皿இ`)
  • ⌇●﹏●⌇
  • (ฅ´ω`ฅ)
  • (╯°A°)╯︵○○○
  • φ( ̄∇ ̄o)
  • ヾ(´・ ・`。)ノ"
  • ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
  • (ó﹏ò。)
  • Σ(っ °Д °;)っ
  • ( ,,´・ω・)ノ"(´っω・`。)
  • ╮(╯▽╰)╭
  • o(*////▽////*)q
  • >﹏<
  • ( ๑´•ω•) "(ㆆᴗㆆ)
  • 😂
  • 😀
  • 😅
  • 😊
  • 🙂
  • 🙃
  • 😌
  • 😍
  • 😘
  • 😜
  • 😝
  • 😏
  • 😒
  • 🙄
  • 😳
  • 😡
  • 😔
  • 😫
  • 😱
  • 😭
  • 💩
  • 👻
  • 🙌
  • 🖕
  • 👍
  • 👫
  • 👬
  • 👭
  • 🌚
  • 🌝
  • 🙈
  • 💊
  • 😶
  • 🙏
  • 🍦
  • 🍉
  • 😣
  • 颜文字
  • Emoji
  • Bilibili
0 条评论
没有评论
Powered by Twikoo v1.6.44
Twikoo 评论管理
密码