将DockerComposeContainer用于远程Docker守护程序

时间:2018-07-19 20:33:48

标签: java docker docker-compose testcontainers

我正在使用DockerComposeContainer部署自定义docker-compose.yml,它描述了集成测试期间使用的环境。到目前为止,这一直很好。我最近开始使用远程Docker守护程序(而非本地Docker守护程序)来远程执行某些集成测试,而DockerComposeContainer遇到了问题。

我当前的挑战是DockerComposeContainer接受File,即到docker-compose.yml的路径。远程Docker守护程序的问题在于<root path project>/src/test/resources/docker-compose.yml的完整路径将无法在运行远程Docker守护程序的主机上解析,因为该路径不存在于该路径:

[INFO] Docker host IP address is 10.0.0.101
[INFO] Connected to docker: 
...
[INFO] Pulling docker image: alpine/socat:latest. Please be patient; this may take some time but only needs to be done once.
[INFO] Pulling docker image: docker/compose:1.21.0. Please be patient; this may take some time but only needs to be done once.
[INFO] Creating container for image: docker/compose:1.21.0
[INFO] Starting container with ID: bf33960e45ca4ce589860e6bde62fb85f8847e2f12516efd38ecd64073455915
[INFO] Container docker/compose:1.21.0 is starting: bf33960e45ca4ce589860e6bde62fb85f8847e2f12516efd38ecd64073455915
[ERROR] Could not start container
java.lang.IllegalStateException: Container did not start correctly.
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:272)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:226)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:224)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:209)
    at org.testcontainers.containers.ContainerisedDockerCompose.invoke(DockerComposeContainer.java:556)
    at org.testcontainers.containers.DockerComposeContainer.runWithCompose(DockerComposeContainer.java:219)
    at org.testcontainers.containers.DockerComposeContainer.createServices(DockerComposeContainer.java:173)
    at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:160)
    at org.testcontainers.containers.DockerComposeContainer.starting(DockerComposeContainer.java:129)
[ERROR] Container log output (if any) will follow:
[INFO] STDERR: .FileNotFoundError: [Errno 2] No such file or directory: '/home/doplon/projectabc/src/test/resources/docker-compose.yml'

我正在寻找有关如何立即进行操作的建议。

  • 功能/更改请求可能是DockerComposeContainer也接受String(而不是File)并持有docker-compose.yml文件的内容。就是说,我不确定实现的样子,因为有一个中间容器负责启动docker-compose.yml。也许第二种方法更可行。
  • 另一个功能/更改请求是将docker-compose.yml保留在一个临时Docker卷中。这样,负责启动docker-compose.yml的容器可以在卷上挂载,并且可以轻松读取它。由于将在远程Docker守护程序上创建Docker卷,因此上述问题消失了。
  • 也许还有其他方法不涉及Testcontainers来源的改变?

非常感谢任何反馈。我当然愿意尝试或破解某些东西。

0 个答案:

没有答案