简体   繁体   English

如何将本地 Docker 映像与 testcontainers 一起使用?

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

相关问题 测试容器不使用本地 docker 映像 - Testcontainers doesn't use local docker image 如何强制测试容器使用特定的 docker 图像? - How to force Testcontainers to use specific docker image? 如何从 Liquibase 更改日志中为 Testcontainers 构建 Docker 映像? - How to build Docker image for Testcontainers from Liquibase changelogs? 在Testcontainers中使用自定义DB docker-image - Using custom DB docker-image with Testcontainers 如何在现有应用程序中使用测试容器? - How to use testcontainers in existing application? 在 testcontainers 中使用 PostgreSQLContainer 和图像 on-the-fly - Use PostgreSQLContainer with image on-the-fly in testcontainers 使用测试容器运行带有自定义端口的 ES docker 图像 - Run ES docker image with custom port using testcontainers 使用 Jib 获取特定版本的图像(Maven、Docker、testcontainers) - Getting a specific version of an image with Jib (Maven, Docker, testcontainers) 测试容器超时等待容器端口打开,使用 Elasticsearch docker 镜像 - Testcontainers timed out waiting for container port to open, with Elasticsearch docker image 使用Artifactory代理到Docker Hub,在防火墙内部使用testcontainer进行测试 - Use Artifactory proxy to Docker Hub with testcontainers inside a firewall for testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM