【问题标题】:How to push a docker image to ecr repo in moto server如何将 docker 镜像推送到 moto 服务器中的 ecr repo
【发布时间】:2021-04-11 17:03:30
【问题描述】:

我正在使用命令运行 moto 服务器

moto_server ecr -p 5000 -H 0.0.0.0

我使用 moto 服务器和命令创建了一个 ECR 存储库,

aws ecr create-repository --repository-name test --endpoint-url http://localhost:5000 --region us-east-1

现在有人可以帮忙看看如何将 docker 镜像推送到这个使用 moto 服务器创建的 ecr 存储库吗?

【问题讨论】:

  • 这个 moto 服务器是 aws ecr 的模拟吗?
  • 是的,moto 服务器是许多 aws 服务的模拟。 github.com/spulec/moto
  • ECR 是一个 docker 注册表,它是在某个端口上运行的服务器。如果 moto 能够模拟它,则应该可以使用一些端点进行测试。使用它来测试您的模拟 ecr 服务器:curl -X GET https://myregistry:5000/v2/_catalog。我认为在你的情况下是本地主机。也尝试使用netstat -tulpn para linux 或netstat -aon for windows 获取使用的端口。如果这行得通。图片上传是小菜一碟:b
  • TIL moto 存在 :) 。如果这是经典的 ECR,那么您首先需要验证 (see here) 才能推送图像,然后您需要使用类似于 docker push aws_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/YOURIMAGE:TAG 的方式推送图像。渴望了解 moto 究竟是如何模拟这一切的(如果有的话)。
  • @JRichardsz 对于 moto 的 ECR,没有私有注册表。请检查我的解决方法。

标签: docker docker-registry amazon-ecr moto


【解决方案1】:

查看代码后,我发现put-image 命令实际上将图像添加到存储库。在ECR by AWS 的情况下,AWS 使用此命令添加通过 docker push 命令上传的图像的元数据。

# aws ecr put-image --repository-name test --region us-east-1 --image-manifest test --endpoint-url http://localhost:5000 --image-tag v1
{
    "image": {
        "registryId": "012345678910",
        "repositoryName": "test",
        "imageId": {
            "imageDigest": "sha256:a6698ae96409579a4f8ac96f5e5f276467b3f62d184c9e6db537daeedb9dd939",
            "imageTag": "v1"
        },
        "imageManifest": "test"
    }
}

# aws ecr list-images --repository-name test --region us-east-1 --endpoint-url http://localhost:5000
{
    "imageIds": [
        {
            "imageDigest": "i don't know",
            "imageTag": "v1"
        }
    ]
}

幸运的是,我的代码不需要从 ECR 存储库中推送或拉取图像。如果是这种情况,此方法可能不起作用。

【讨论】:

    猜你喜欢
    • 2020-01-30
    • 2020-02-13
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多