AWS ECS异常Container.image包含无效的char意味着什么?

时间:2018-03-04 10:04:59

标签: amazon-web-services elastic-beanstalk amazon-ecs

我们在工作流程中使用CircleCi,以便在ElasticBeanstalk服务器上将PHP站点部署为docker镜像。 CircleCi中的build个作业定义如下:

deploy:
    docker:
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache \
              py-pip=9.0.0-r1
            pip install \
              awscli \
              awsebcli --upgrade
      - run:
          name: Login to AWS
          command: |
            login="$(aws ecr get-login --no-include-email --region us-west-2)"
            ${login}
      - run:
          name: Deploy to Elastic Beanstalk
          command: |
            echo "Commit sha: ${CIRCLE_SHA1}"
            if [ "${CIRCLE_BRANCH}" == "docker" ]; then
              sed -i'' -e "s/%BUILD_NUM%/${CIRCLE_SHA1}/g" Dockerrun.aws.json
              eb deploy sales-web -l $CIRCLE_SHA1
            fi

containerDefinitions下的Dockerrun.aws.json中,我们有(####是ECS中应用程序ID和存储库名称的正确值)

{
            "essential": true,
            "image": "####.dkr.ecr.us-west-2.amazonaws.com/####:%BUILD_NUM%",
            "memory": 2048,
            "name": "web-container",
            "portMappings": [
                {
                    "containerPort": 80,
                    "hostPort": 80
                }
            ]
        }

登录AWS 步骤成功并上传图片,环境sales-web开始更新但失败

2018-03-02 16:10:41 UTC+0200    ERROR   Failed to deploy application.
2018-03-02 16:10:41 UTC+0200    ERROR   Service:AmazonECS, Code:ClientException, Message:Container.image contains invalid characters., Class:com.amazonaws.services.ecs.model.ClientException
2018-03-02 16:09:52 UTC+0200    INFO    Environment update is starting.

我们确保图像构建正确(我们可以将它上传到CircleCi服务器,启动容器并运行phpunit测试)。项目的根目录中有.elasticbeanstalk文件夹,其中包含有效的config.yml文件。

尝试并用Google搜索了2天没有运气。 将不胜感激任何帮助或指导,以了解此错误消息的含义。如果需要任何其他细节,我会提供给他们,请问。

1 个答案:

答案 0 :(得分:1)

当我在一个变量的末尾有一个额外的}时,我就使用了terraform。

您可能想做的是在docker中构建映像名称,并对其进行回显以供审核。

将您的Dockerrun.aws.json更新为:

...
"image": "%IMAGE_NAME",
...

,然后将您的圈子构建更新为:

  - run:
      name: Deploy to Elastic Beanstalk
      command: |
        echo "Commit sha: ${CIRCLE_SHA1}"
        if [ "${CIRCLE_BRANCH}" == "docker" ]; then
          IMAGE_NAME=####.dkr.ecr.us-west-2.amazonaws.com/####:${CIRCLE_SHA1}
          echo "IMAGE_NAME is $IMAGE_NAME"
          sed -i'' -e "s/%IMAGE_NAME%/${IMAGE_NAME}/g" Dockerrun.aws.json
          eb deploy sales-web -l $CIRCLE_SHA1
        fi

然后,如果失败,则在构建过程中复制IMAGE_NAME输出,然后尝试使用

自己提取图像
$(aws ecr get-login --no-include-email --region us-west-2)
docker pull <IMAGE_NAME>

我敢打赌,它将出现一个错误,您可以进行故障排除。