Files
app-product/swarm.yml
编码猿 3c3309af28
All checks were successful
build and push / build-and-push (push) Successful in 2m25s
frontend
2025-10-07 21:05:59 +08:00

41 lines
1.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

version: "3.8" # Docker Compose 文件版本3.8 支持 Swarm 模式的所有功能
networks:
frontend: # 定义 frontend 网络
driver: overlay # 使用 overlay 网络驱动,支持跨主机通信
services:
app-product:
image: registry.bmycode.help/app-product:{{IMAGE_TAG}}
ports:
- target: 80 # 容器内部端口
published: 1301 # 宿主机对外暴露端口
protocol: tcp # 协议类型
mode: ingress # 模式:使用路由网格
deploy:
replicas: 3 # 副本数量,在集群中运行 3 个容器实例
placement:
max_replicas_per_node: 1 # 每个 Swarm 节点最多运行 1 个副本,确保高可用性
restart_policy:
condition: any # 重启条件:任何情况下容器退出都重启
delay: 5s # 重启延迟 5 秒
max_attempts: 3 # 最大重启尝试次数
update_config: # 滚动更新配置
parallelism: 1 # 并行更新数量:一次只更新 1 个容器
delay: 10s # 更新间隔:每个容器更新后等待 10 秒再更新下一个
failure_action: rollback # 更新失败时自动回滚到上一版本
order: start-first # 更新顺序:先启动新容器,确认健康后再停止旧容器
rollback_config: # 回滚配置
parallelism: 1 # 回滚时并行数量
delay: 5s # 回滚延迟
resources: # 资源限制
limits: # 资源上限
cpus: "0.50" # 最多使用 0.5 个 CPU 核心
memory: "256M" # 最多使用 256MB 内存
reservations: # 资源预留
cpus: "0.25" # 预留 0.25 个 CPU 核心
memory: "128M" # 预留 128MB 内存
networks:
- frontend # 连接到 frontend 网络