aws ecs 优化 AMI 中的私有 docker 注册表身份验证不成功

Private docker registry authentication in aws ecs optimized AMI is not successful

我正在编写用于创建 ECS 自动缩放集群的 Terraform 脚本。 我已经创建了一个集群并将 ec2 容器实例添加到 it.My 任务定义文件中,该文件包含一个来自私有 docker repository.I 的图像,请浏览 aws 官方文档并找到 Private Registry Authentication 并尝试了那里描述的两种方法。

  1. 使用 dockercfg
  2. docker方式

我将我的 ecs.config 文件放在 S3 存储桶中,并在实例启动期间将用户数据作为

#!/bin/bash
yum install -y aws-cli
aws s3 cp s3://<my_bucket_name>/ecs.config /etc/ecs/ecs.config

在我的第二种方法中,我将使用的数据传递为

echo "ECS_ENGINE_AUTH_TYPE=docker" >>/etc/ecs/ecs.config
echo "ECS_ENGINE_AUTH_DATA={"https://index.docker.io/v1/":{"username":"my_name","password":"my_password","email":"email@example.com"}}"  >>/etc/ecs/ecs.config

登录我的容器实例时,我在我的 /etc/ecs/ecs.config 中找到了数据,但是当我尝试手动拉取图像时,我显示了一个没有找到图像的错误。

然后我在那里尝试 docker 登录命令并手动输入我的凭据并尝试再次拉取该图像,最终它成功了。

我不确定是否有办法通过用户数据自动在 ecs 优化映像中实现私有 docker 注册表身份验证,或者如果我做错了什么。

请帮我解决这个问题。

when I try to pull the image manually I shows me an error that no image found

您使用的方法为 ECS 代理提供私有注册表凭据,但不为 Docker CLI(Docker CLI 将其凭据数据存储在不同的位置)。由于您已经为代理配置了凭据,因此您应该能够 运行 引用私有注册表中图像的任务定义,而无需从 Docker CLI 手动提取图像。

编辑: 由于您引用 echo 命令的方式,您在实例上的 /etc/ecs/ecs.config 文件中似乎有错误。您需要更改此行:

echo "ECS_ENGINE_AUTH_DATA={"https://index.docker.io/v1/":{"username":"my_name","password":"my_password","email":"email@example.com"}}"  >>/etc/ecs/ecs.config

echo 'ECS_ENGINE_AUTH_DATA={"https://index.docker.io/v1/":{"username":"my_name","password":"my_password","email":"email@example.com"}}'  >>/etc/ecs/ecs.config