[英]How to pull a private docker image from AWS ECR to use with the Testcontainers library in Java
I am trying to programmatically create and spin up a MongoDBContainer from a docker image hosted in a private AWS ECR repository.我正在尝试通过托管在私有 AWS ECR 存储库中的 docker 图像以编程方式创建和启动 MongoDBContainer。 This will be used for automated integration tests, will be run locally and within CICD pipelines.这将用于自动化集成测试,将在本地和 CICD 管道内运行。 But that doesn't work (see 2.).但这不起作用(见 2.)。 When I pull the image from DockerHub (see 1.) it works.当我从 DockerHub 中拉取图像时(请参阅 1.),它可以正常工作。 Code I have so far is:我到目前为止的代码是:
@Testcontainers
@AutoConfigureDataMongo
public interface MongoTestContainer {
// 1. This pull the image directly from DockerHub, and it works.
//@Container MongoDBContainer mongoDBContainer = new
//MongoDBContainer("mongo:5.0.11");
// 2. This should pull the image from AWS ECR but doesn't work.
@Container MongoDBContainer mongoDBContainer = new
MongoDBContainer("<account>.dkr.ecr.<region>.amazonaws.com/<imageName>:<version>");
@DynamicPropertySource
static void setProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.mongodb.uri", mongoDBContainer::getReplicaSetUrl);
}
}
Any ideas?有任何想法吗?
Kind regards, John亲切的问候,约翰
Using the 2nd approach should fail throwing an exception and the message should provide the fix which I would mention below.使用第二种方法应该会抛出异常失败,消息应该提供我将在下面提到的修复方法。 There are two options:有两种选择:
~/.testcontainers.properties
add hub.image.name.prefix=custom.dockerhub.repository/
在~/.testcontainers.properties
添加hub.image.name.prefix=custom.dockerhub.repository/
new MongoDBContainer(DockerImageName.parse("<account>.dkr.ecr.<region>.amazonaws.com/<imageName>:<version>").asCompatibleSubstituteFor("mongo")
使用new MongoDBContainer(DockerImageName.parse("<account>.dkr.ecr.<region>.amazonaws.com/<imageName>:<version>").asCompatibleSubstituteFor("mongo")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.