简体   繁体   English

使用测试容器作为 Dockerfile 的一部分运行测试

[英]Running test with testcontainers as part of a Dockerfile

My dockerfile looks something like this:我的 dockerfile 看起来像这样:

FROM maven:3-jdk-11-slim
COPY pom.xml .
COPY src src
RUN mvn clean install

That means that part of the build is the execution of the unit tests.这意味着构建的一部分是单元测试的执行。 Some of the unit tests use a testcontainer.一些单元测试使用测试容器。 Running mvn clean install on my local machine works fine, but running docker build. -t my-app在我的本地机器上运行mvn clean install工作正常,但运行docker build. -t my-app docker build. -t my-app doesn't because the testcontainers won't start. docker build. -t my-app不会,因为测试容器不会启动。

(...)
15:54:38.793 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
15:54:38.794 [ducttape-0] DEBUG com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: org.testcontainers.dockerclient.transport.okhttp.OkHttpDockerCmdExecFactory$1@355cb260
15:54:39.301 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
15:54:39.301 [ducttape-0] DEBUG com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: org.testcontainers.dockerclient.transport.okhttp.OkHttpDockerCmdExecFactory$1@1c1a1359
15:54:39.469 [main] ERROR org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy - ping failed with configuration Environment variables, system properties and defaults. Resolved dockerHost=unix:///var/run/docker.sock due to org.rnorth.ducttape.TimeoutException: Timeout waiting for result with exception
org.rnorth.ducttape.TimeoutException: Timeout waiting for result with exception
(...)

I've seen examples of running docker run with working testcontainers, but how do I make my docker build work?我已经看到了运行docker run与工作测试容器一起运行的示例,但是如何使我的docker build工作?

Help is much appreciated.非常感谢您的帮助。

For future reference: I believe this is simply not possible.供将来参考:我相信这根本不可能。

docker run allows you to mount the Docker socket (and thus access the host's Docker daemon) with -v /var/run/docker.sock:/var/run/docker.sock . docker run允许您安装 Docker 套接字(从而访问主机的 Docker 守护程序) -v /var/run/docker.sock:/var/run/docker.sock

docker build doesn't support such an argument. docker build不支持这样的论点。

My workaround will be to modify my Dockerfile to RUN mvn clean install -Dmaven.test.skip=true and run the unit tests separately.我的解决方法是将我的 Dockerfile 修改为RUN mvn clean install -Dmaven.test.skip=true并单独运行单元测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Dockerfile testcontainers 无法连接到 Ryuk - Dockerfile testcontainers Can not connect to Ryuk 如果测试失败,如何配置测试容器以使数据库容器保持运行? - How to configure testcontainers to leave database container running if a test fails? Gitlab CI 上的 TestContainers 集成测试 - TestContainers integration test on Gitlab CI 没有为集成测试运行 testcontainers 的 Localstack 模块 - Localstack module of testcontainers is not running for integration tests testcontainers-由于测试失败,Maven构建失败 - testcontainers - maven build fails due to test failures Spring 使用 testcontainers 启动测试 postgresql - Spring boot test using testcontainers postgresql 在没有测试容器启动的情况下运行 SpringBootTest 上下文 - Running SpringBootTest Context Without Testcontainers Launch 如何在 spring 启动集成测试期间正确连接到测试容器 redis? - How to connect to testcontainers redis correctly during spring boot integration test? 在 spock 测试中获取对默认 java 容器(TestContainers)的访问权限 - Get the access to default java container (TestContainers) in spock test Testcontainers MS SQL Server Module 一直在循环,从不进入测试 - Testcontainers MS SQL Server Module stays in a loop and never enters the test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM