首页 > 解决方案 > AWS Elastic Beanstalk 'CannotPullContainerError' 用于私有 Docker 映像(多实例)

问题描述

我有一个单实例弹性 beanstalk 环境,它运行一个 docker 镜像,该镜像在 Dockerhub 上作为私有镜像托管。这工作正常。我正在尝试创建一个新的多容器环境,它运行完全相同的图像(加上另一个,不在我的代码示例中)。在多容器环境中,我无法让弹性 beanstalk 启动我的 docker 映像,我收到以下错误:

ECS task stopped due to: Task failed to start. (img1_name: img2_name: CannotPullContainerError: Error response from daemon: pull access denied for user/repo, repository does not exist or may require 'docker login': denied: requested access to the resource is denied)

这是我的单实例环境的 dockerrun:

{
  "AWSEBDockerrunVersion": "1",
  "Authentication": {
    "Bucket": "my_bucket",
    "Key": ".dockercfg"
  },
  "Image": {
    "Name": "user/repo:tag",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": 5000,
      "HostPort": 443
    }
  ],
  "Logging": "/var/log/nginx"
}

这是 .dockerfcg 文件:

{
    "auths": {
        "https://index.docker.io/v1/": {
            "auth": "my_token"
        }
    }
}

同样,上述工作正常。

我的多实例 dockerrun 文件如下:

{
  "AWSEBDockerrunVersion": "2",
  "authentication": {
    "bucket": "my_bucket",
    "key": ".dockercfg"
  },
  "containerDefinitions": [
    {
      "name": "img_name",
      "image": "user/repo:tag",
      "essential": true,
      "memoryReservation": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 5000
        }
      ]
    }
  ],
  "Logging": "/var/log/nginx"
}

我已经 ssh-ed 到我的 elastic-beanstalk 实例并运行以下命令以检查它是否能够从我的 s3 存储桶访问 .dockercfg: aws s3api get-object --bucket mybucket --key dockercfg dockercfg

我还尝试了 .dockercfg 文件的各种不同格式,包括...

{
  "https://index.docker.io/v1/": {
    "auth": "zq212MzEXAMPLE7o6T25Dk0i",
    "email": "email@example.com"
  }
}
{
  "auths": {
    "https://index.docker.io/v1/": {
      "auth": "zq212MzEXAMPLE7o6T25Dk0i"
    }
  }
}

我为此烦恼不已,我在这里和 AWS 论坛上发现了一些类似的主题,但似乎没有什么能解决我的问题。非常感谢任何帮助。

标签: amazon-web-servicesdockeramazon-elastic-beanstalkdockerhub

解决方案


推荐阅读