问题描述
我们使用 Testcontainers 编写了端到端测试。使用以下 Testcontainers 方法加载 docker-compose 文件:
@Container
public static final DockerComposeContainer<?> COMPOSE_CONTAINER =
new DockerComposeContainer<>(new File("src/test/resources/docker-compose-test.yml"))
.withLocalCompose(true)
.withExposedService(ZOOKEEPER_SERVICE,ZOOKEEPER_PORT)
.withExposedService(broKER_SERVICE,broKER_PORT)
.withExposedService(broKER_SERVICE,broKER_PORT_LOCALHOST)
.withExposedService(SCHEMA_REGISTRY_SERVICE,SCHEMA_REGISTRY_PORT)
.withExposedService(VAULT_SERVICE,VAULT_PORT)
.withExposedService(ELASTICSEARCH_SERVICE,ELASTICSEARCH_PORT_1)
.withExposedService(ELASTICSEARCH_SERVICE,ELASTICSEARCH_PORT_2)
.waitingFor(ELASTICSEARCH_SERVICE,Wait.forHttp("/").forStatusCode(200))
.waitingFor(VAULT_SERVICE,Wait.forHttp("/").forStatusCode(200))
.waitingFor(SCHEMA_REGISTRY_SERVICE,Wait.forHttp("/subjects").forStatusCode(200));
它在本地工作,但在我们的 Gitlab-CI 测试阶段失败。我们尝试将 docker-compose 添加到舞台,但它仍然不起作用。测试阶段已编写如下:
test:
stage: test
services:
- docker:dind
script:
- apk add --no-cache docker-compose
- docker-compose --version
- mvn clean test -Djavax.net.ssl.trustStore=${CI_PROJECT_DIR}/src/main/resources/cacerts -Djavax.net.ssl.trustStorePassword=${TRURST_STORE_PWD}
artifacts:
reports:
junit: ./target/surefire-reports/*.xml
管道中的错误是:
Time elapsed: 101.927 s <<< ERROR!
org.testcontainers.containers.ContainerLaunchException: Local Docker Compose not found. Is docker-compose on the PATH?
我希望有人已经设置了类似的东西并且会帮助我们:)
最好的问候。
解决方法
可能是因为你不能只使用 docker:dind,因为那是 docker 中的 docker,你需要 dcind,它是 docker 中的 docker compose。我不确定您是否可以尝试 docker:dcind 或者是否有另一个 dcind 图像可以在 docker hub 上尝试。