[英]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.