如何让docker-maven-plugin在运行集成测试之前等待RabbitMQ容器完全启动?
这是我在pom.xml中使用的插件配置
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>start-rabbitmq-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<images>
<image>
<alias>rabbitmq</alias>
<name>rabbitmq:3.6.10-management</name>
<run>
<log>
<prefix>RABBITMQ</prefix>
<color>cyan</color>
</log>
<namingStrategy>alias</namingStrategy>
<ports>
<port>5672:5672</port>
<port>15672:15672</port>
</ports>
</run>
</image>
</images>
</configuration>
</execution>
<execution>
<id>stop-rabbitmq-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>当它开始执行RabbitMQ时,它仍在初始化并失败,因为服务器不可用。
发布于 2017-08-09 21:09:13
我设法找到了一种更自信的方法来检查RabbitMQ的状态。当我使用rabbitmq:3.6.10-management docker镜像时,我可以检查localhost:15672上的管理url是否在运行:
<wait>
<http>
<url>http://localhost:15672</url>
<method>GET</method>
<status>200..399</status>
</http>
<time>10000</time>
</wait>wait配置会检查获取管理url的返回值,最长10秒,直到它在指定的HTTP响应状态范围内,但RabbitMQ通常在2到3秒内启动。
发布于 2017-08-04 20:24:38
“启动容器时,是否可以阻止执行,直到满足某些条件”
https://dmp.fabric8.io/#start-wait
您可以使用log从RabbitMQ容器中通过wait获取一些日志输出
Regular expression which is applied against the log output of an container and blocks until the pattern is matched. You can use (?s) in the pattern to switch on multi line matching.
https://stackoverflow.com/questions/45506461
复制相似问题