通过GitLabpipe道将Docker容器部署到EC2容器服务时出错

我正在尝试使用GitLabpipe道将Docker容器部署到EC2容器服务中。 我已经在AWS中创build了集群,并且还运行了2个实例。 问题是,一旦命令

ecs-cli compose --file ./Documents/Development/workillence/docker-compose-test.yml service up --container-name testContainer --container-port 8080 #--role arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole --target-group-arn arn:aws:elasticloadbalancing:us-east-2:084622260700:targetgroup/TestTG/af0fbec5b9cc869f 

被执行我收到以下错误:

 WARN[0000] Skipping unsupported YAML option for service... option name=build service name=testContainer ERRO[0001] Error registering task definition error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" family=ecscompose-workillence ERRO[0001] Create task definition failed error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" FATA[0001] ClientException: Container.image should not be null or empty. 

这是我的AWS回购的截图:

在这里输入图像说明

图像似乎不是空的。

这是我的CI文件的样子:

 image: docker:latest services: - docker:dind stages: - build - deploy testBuild: stage: build script: - docker version - docker build -t 084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest app/ - docker images - docker login -u AWS -p <password> 084622260700.dkr.ecr.us-east-2.amazonaws.com - docker push 084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest testDeploy: stage: deploy image: python:3-alpine variables: AWS_REGION: "us-east-2" AWS_ACCESS_KEY_ID: "key" AWS_SECRET_ACCESS_KEY: "key" PROD_TARGET_GROUP_ARN: "arn:aws:elasticloadbalancing:us-east-2:084622260700:targetgroup/TestTG/af0fbec5b9cc869f" ECS_CLUSTER: "testCluster" AWS_KEY_PAIR: "testKP.pem" AWS_VPC: "vpc-0419416d" AWS_SUBNETS: "subnet-ad6cdfe0,subnet-ad6cdfe0,subnet-0fc1aa74" AWS_INSTANCE_TYPE: "t2.micro" AWS_INSTANCE_COUNT: "2" #Number of instances to scale to AWS_ROLE: "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole" before_script: ##### Install AWS ECS-CLI ##### - apk add --update curl - curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest - chmod +x /usr/local/bin/ecs-cli script: ##### Configure ECS-CLI, run the container and scale to 2 instances ##### - ecs-cli configure --region $AWS_REGION --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster $ECS_CLUSTER - ecs-cli up --keypair $AWS_KEY_PAIR --capability-iam -c $ECS_CLUSTER --instance-type t2.micro --size 2 --vpc $AWS_VPC --subnets $AWS_SUBNETS --force ##### This docker-compose.yml is the one described above ##### - ecs-cli compose --file docker-compose.yml service up --target-group-arn $PROD_TARGET_GROUP_ARN --container-name app --container-port 8080 --role $AWS_ROLE - ecs-cli compose --file docker-compose.yml service scale 2 environment: name: ci ##### This is the URL seen under 'DNS name' when the LB was created ##### url: TestLB-1717492587.us-east-2.elb.amazonaws.com only: - aws 

这就是撰写文件的样子:

  app: image: 084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest command: yarn run start-dev links: - mongodb - redis - elasticsearch ports: - '8000:8000' - '5858:5858' - '9229:9229' - '80:8080' environment: NODE_ENV: local volumes: - ./testrepo/.:/opt/app mongodb: build: docker/definitions/mongo ports: - "27017:27017" redis: build: docker/definitions/redis ports: - "6379:6379" elasticsearch: build: docker/definitions/elasticsearch ports: - "9200:9200" - "9300:9300" 

你有没有遇到过相同或类似的问题,可能你是怎么解决的?

问题很清楚。 您的撰写文件是用于构build,并没有图像

 WARN[0000] Skipping unsupported YAML option for service... option name=build service name=testContainer ERRO[0001] Error registering task definition error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" family=ecscompose-workillence ERRO[0001] Create task definition failed error="ClientException: Container.image should not be null or empty.\n\tstatus code: 400, request id: 27277917-8d8e-11e7-8cb2-8d5ad96f4568" FATA[0001] ClientException: Container.image should not be null or empty. 

所以你需要的是

  mongodb: build: docker/definitions/mongo image: <image from aws or docker hub> ports: - "27017:27017" redis: build: docker/definitions/redis image: <image from aws or docker hub> ports: - "6379:6379" elasticsearch: build: docker/definitions/elasticsearch image: <image from aws or docker hub> ports: - "9200:9200" - "9300:9300" 

一旦你添加它应该工作。 如果build值产生问题,则可以使用两个单独的撰写文件。 一个具有构build值,另一个具有图像值