[英]How to use local Docker image with testcontainers?
I want to use a local-only Docker image with testcontainers .我想在testcontainers 中使用仅限本地的 Docker 映像。
The code looks like this:代码如下所示:
new GenericContainer("rserver:latest")...
However it looks like another image with same name is fetched from a remote registry.然而,看起来另一个同名的图像是从远程注册表中获取的。
How can I force testcontainers to use a local image?如何强制测试容器使用本地图像?
I know this answer is too late but it can be useful for others who has exactly the same issue.我知道这个答案为时已晚,但对于遇到完全相同问题的其他人来说可能很有用。
If you are already have the image you want, try to implicitly set the image Pull Policy for your container to default:如果您已经拥有所需的镜像,请尝试将容器的镜像拉取策略隐式设置为默认值:
GenericContainer container = new GenericContainer("someImage")
.withImagePullPolicy(PullPolicy.defaultPolicy());
The default image Pull Policy tells the Docker to pull the image from a remote repository only if it does not exist locally.默认的镜像拉取策略告诉 Docker 只有在本地不存在的情况下才从远程存储库中拉取镜像。
Note that this method (withImagePullPolicy(..)) is available only with latest versions of TestContainers dependency.请注意,此方法 (withImagePullPolicy(..)) 仅适用于最新版本的 TestContainers 依赖项。 I use 1.14.3.
我使用 1.14.3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.