[英]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?任何提示如何处理此类问题?
Please see chapter 7.4 here, it really works: https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html请在此处查看第7.4章,它确实有效: https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.ZFC35FDC70D5FC69D269883A822C
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.