简体   繁体   English

如何从 AWS ECR 中提取私有 docker 图像以与 Java 中的 Testcontainers 库一起使用

[英]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:有两种选择:

  1. In ~/.testcontainers.properties add hub.image.name.prefix=custom.dockerhub.repository/~/.testcontainers.properties添加hub.image.name.prefix=custom.dockerhub.repository/
  2. Use 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.

相关问题 如何在 Githubactions 中从 ECR 中提取 docker 图像 - How to pull docker image from ECR in Githubactions 如何从 Google Cloud Composer 的 Kube.netesPodOperator 中的私有 Docker 注册表中提取图像? - How to pull image from private Docker registry in KubernetesPodOperator of Google Cloud Composer? 如何使用 buildspec.yml 在 AWS CodePipeline 中从 Dockerfile 构建图像,然后推送到 ECR? - How to build Image from Dockerfile in AWS CodePipeline using buildspec.yml, and then push to ECR? AWS Lambda from cross account ECR: Lambda 没有访问ECR镜像的权限 - AWS Lambda from cross account ECR : Lambda does not have permission to access the ECR image Terraform部署Docker容器到aws ecr - Terraform deployment of Docker Containers to aws ecr 有没有人有用于将单个构建的 docker 图像推送到不同 AWS 帐户上的两个不同 ECR 的示例构建规范? - Does anyone have a sample buildspec for pushing single built docker image into two different ECR on different AWS accounts? 将图像推送到 ECR 仅适用于私有存储库 - Push image to ECR works for private repositories only ECS 服务无法从 ECR 拉取 - ECS service cannot pull from ECR 如何从 AWS ECR 容器注册表中删除未标记的图像 - How to delete untagged images from AWS ECR Container Registry 将 AWS ECR 与 portainer 推/拉图像一起使用不起作用 - Using AWS ECR with portainer push/pull images not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM