仅当副本完成启动时 Docker 群路由 [英] Docker swarm route only when replica has finished starting

查看:46
本文介绍了仅当副本完成启动时 Docker 群路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个 docker swarm 配置,用于启动复制 x 次的 Java 网络服务器映像.现在,服务器需要时间来启动(约 40 秒),而容器本身则快速启动.

I have set up a docker swarm config that starts a java webserver image replicated x times. Now, the servers take it's time to start up (~40seconds) while the container itself is started quickly.

问题是,docker 会在容器启动后立即开始路由到容器,但不知道容器内的服务是否已准备好处理请求,而在我的情况下,这不是立即

The problem is, docker starts routing to containers as soon as they are up, without knowing if the service inside the container is ready to serve requests, which in my case it is not immediately

配置 docker swarm 以使其仅路由到服务器接受请求的容器的惯用方法是什么?

What is the idiomatic way to configure docker swarm so, that it only routes to containers where the server is accepting requests?

推荐答案

所以有一个healtcheck 部分用于部署撰写文件,可以用来确定容器是否健康.

So there is a healtcheck section for the deployment of the compose file which one can use to make sure a container is healthy or not.

healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost:3482/monitoring/health"]
  interval: 10s
  timeout: 5s
  retries: 3
  start_period: 1m

这样做会确保在运行状况 api 返回有效响应时首先使用容器.

This will do it and make sure a container will be used first if the health api returns a valid response.

这篇关于仅当副本完成启动时 Docker 群路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆