How do I deploy updated Docker images to Amazon ECS tasks?

前端 未结 12 1080
灰色年华
灰色年华 2021-01-29 22:00

What is the right approach to make my Amazon ECS tasks update their Docker images, once said images have been updated in the corresponding registry?

12条回答
  •  隐瞒了意图╮
    2021-01-29 22:43

    Ran into same issue. After spending hours, have concluded these simplified steps for automated deployment of updated image:

    1.ECS task definition changes: For a better understanding, let's assume you have created a task definition with below details (note: these numbers would change accordingly as per your task definition):

    launch_type = EC2
    
    desired_count = 1
    

    Then you need to make the following changes:

    deployment_minimum_healthy_percent = 0  //this does the trick, if not set to zero the force deployment wont happen as ECS won't allow to stop the current running task
    
    deployment_maximum_percent = 200  //for allowing rolling update
    

    2.Tag your image as <your-image-name>:latest . The latest key takes care of getting pulled by the respective ECS task.

    sudo docker build -t imageX:master .   //build your image with some tag
    sudo -s eval $(aws ecr get-login --no-include-email --region us-east-1)  //login to ECR
    sudo docker tag imageX:master .dkr.ecr.us-east-1.amazonaws.com/:latest    //tag your image with latest tag
    

    3.Push to the image to ECR

    sudo docker push  .dkr.ecr.us-east-1.amazonaws.com/:latest
    

    4.apply force-deployment

    sudo aws ecs update-service --cluster  --service  --force-new-deployment --region us-east-1
    

    Note: I have written all the commands assuming the region to be us-east-1. Just replace it with your respective region while implementing.

提交回复
热议问题