- 有多个相互交互的应用程序实例(微服务)
- 有这些 Spring Boot 应用程序的 docker 镜像
- 是否可以在测试容器中使用这些 docker 镜像来部署测试以及如何做到这一点
无需考虑此类测试的工作时间和初始化,这不是这种情况下的主要问题。
最佳答案
Testcontainers 提供 GenericContainer,它允许您使用注册表中的图像。例如,假设您有一个名为 myorganization/greetings-service:2.0.0
的服务镜像,该镜像在端口 8080 中监听请求。那么您可以使用:
GenericContainer container = new GenericContainer("myorganization/greetings-service:2.0.0")
.withExposedPort(8080)
.waitingFor(Wait.forHttp("/"));
之后您可以使用 container.getHost()
和 container.getMappedPort(8080)
获取主机和端口。
希望可以帮到你
关于spring-boot - spring boot应用实例如何打包到testcontainers中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72479951/