如何使用 docker 堆栈实现零停机时间



Docker 更新容器,但网络注册需要 10 分钟才能完成,因此在注册新容器时,页面返回 502,因为内部网络仍指向旧容器。 如何在更新到新容器后将旧容器的删除延迟 10 分钟左右? 理想情况下,我想用 docker 堆栈推送这个配置,但我会尽一切努力。 我还应该指出,由于我被迫使用的安全包的某些限制,我现在无法使用副本。

version: '3.7'
services:
xxx:
image: ${xxx}/com.xxx:${xxx}
environment:
- SERVICE_NAME=xxx
- xxx
- _xxx
- SPRING_PROFILES_ACTIVE=${xxx}
networks:
- xxx${xxx}
healthcheck:
interval: 1m
deploy:
mode: replicated
replicas: 1
resources:
limits:
cpus: '3'
memory: 1024M
reservations:
cpus: '0.50'
memory: 256M
labels:
- com.docker.lb.hosts=xxx${_xxx}.xxx.com
- jenkins.url=${xxx}
- com.docker.ucp.access.label=/${xxx}/xxx
- com.docker.lb.network=xxx${_xxx}
- com.docker.lb.port=8080
- com.docker.lb.service_cluster=${xxx}
- com.docker.lb.ssl_cert=xxx.cert
- com.docker.lb.ssl_key=xxx.key
- com.docker.lb.redirects=http://xxx${_xxx}.xxx.com/xxx,https://xxx${_xxx}.xxx.com/xxx
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
update_config:
parallelism: 1
delay: 10s
order: start-first
failure_action: rollback
rollback_config:
parallelism: 0
order: stop-first
secrets:
- ${xxx}
networks:
xxx${_xxx}:
external: true
secrets:
${xxx}:
external: true
xxx.cert:
external: true
xxx.key:
external: true

使用正确的运行状况检查 - 请参阅此处的参考:https://docs.docker.com/compose/compose-file/#healthcheck

所以:

  1. 您需要定义适当的测试以了解新容器何时完全启动(进入testhealthcheck指令(。
  2. 使用start_period指令指定您的 10(左右(分钟方式 - 否则,Docker Swarm 只会杀死您的新容器并且永远不会让它启动。

基本上,一旦您正确进行健康检查,这应该可以解决您的问题。

最新更新