简体   繁体   English

Docker-compose 和容器上的竞争条件取决于其他容器

[英]Docker-compose and race condition on container depending on other container

I have docker-compose which will start multiple containers of Java SpringBoot microservices and one of them, which depends on two others, will fail to start with something like race condition:我有docker-compose它将启动 Java SpringBoot 微服务的多个容器,其中一个依赖于另外两个,将无法以类似竞争条件的方式启动:

Exception thrown from ApplicationListener handling ContextClosedEvent

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'rabbitConnectionFactory': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:208)

When I will stop it and run it manually it will pick up.当我停止它并手动运行它时,它会启动。 When docker-compose will have set restart: on-failure for that service it will pick up on 3rd restart.docker-compose将设置restart: on-failure该服务时,它将在第 3 次重新启动时恢复。

Any tips how to handle such of problem?任何提示如何处理此类问题?

Usually, depends_on is enough.通常,depends_on 就足够了。 Nevertheless, sometimes it may not work properly.然而,有时它可能无法正常工作。 Once I heard about this issue and the recommendation was to use the healthcheck docker option, available at docker v2.3.一旦我听说了这个问题并且建议使用healthcheck选项,该选项可在 docker v2.3 获得。 See guide here .请参阅此处的指南。

I am adding an example using a healthcheck to guarantee the database is up.我正在添加一个使用运行状况检查的示例以保证数据库已启动。 So, only after the healthcheck is ok, they will startup the other apps.因此,只有在健康检查正常后,他们才会启动其他应用程序。

[...]
healthcheck:
  test: ["CMD-SHELL", 'mysql -uroot --database=<db-name> --password=<password> --execute="SELECT 
  count(table_name) > 0 FROM information_schema.tables;" --skip-column-names -B']
  interval: 10s
  timeout: 10s
  retries: 4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 docker-compose中的容器发现 - container discovery in docker-compose Docker-compose:如何知道容器中的jar完成运行并随后启动其他容器的时间 - Docker-compose: how to know when jar inside a container finish to run and later start other container Docker-Compose:如何对 OpenJDK:8 容器进行健康检查? - Docker-Compose: How to healthcheck OpenJDK:8 container? Docker-compose 容器连接到 MySql 不起作用 - Docker-compose container connection to MySql not working Java 容器无法使用 docker-compose 连接到 MYSQL 容器 - Java container cant connect to MYSQL container with docker-compose 在 Docker-Compose 上创建的 docker 容器上运行 ADB - Run ADB on docker container created on Docker-Compose 如何在没有反向代理容器的情况下使用 docker-compose 部署启用 HTTPS 的 Jenkins 容器? - How do I deploy HTTPS enabled Jenkins container using docker-compose WITHOUT a reverse proxy container? 使用 docker-compose 连接到 mongo 容器的 Springboot 容器的 503 错误代码 - 503 error code for Springboot container connecting to mongo container using docker-compose 无法使用 docker-compose 从 Tomcat Docker 容器访问主机 - Unable to reach the host from a Tomcat Docker Container using docker-compose Docker-compose - 为运行 spring boot 独立应用程序的 docker 容器提供基于 XML 的配置 - Docker-compose - Providing XML based configuration to docker container running spring boot standalone application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM