0
我正在嘗試使用GitLab管道將Docker容器部署到EC2容器服務中。我已經在AWS中創建了羣集,並且還運行了2個實例。問題是,一旦執行通過GitLab將Docker容器部署到EC2容器服務時出錯管道
命令我收到以下錯誤:
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"
你曾經面臨相同或相似的問題,可能是如何做你解決了嗎?
我沒有猜測那些服務將在此錯誤中扮演任何角色,我沒有描述,但我將使用外部提供程序來執行mongo,redis和elasticsearch。這意味着它們不會在Docker包內部構建,而且我已經在本地測試了環境並且它可以工作,我可以連接它們中的三個。 有什麼辦法可以在撰寫文件中聲明它們是外部的嗎? –
如果它們是外部的,則將它們從撰寫中刪除。保留兩個組合'-test.yml'和'-prod.yml'。使用'prod'進行AWS部署 –
好的,我測試了它,並再次發生了相同的錯誤。 我用下面的代碼: 'testContainer: 編譯:084622260700.dkr.ecr.us-east-2.amazonaws.com/testrepo:latest 命令:絲線行進啓動開發 端口: - 「8000 :8000' - '5858:5858' - '9229:9229' - '80:8080' 環境: NODE_ENV:本地 卷: - ./testrepo /.:/選擇/ app' –