Search code examples
amazon-web-servicesdockeramazon-ec2amazon-ecsdocker-image

How to update EC2 instance after pushing new image version


Currently I have a docker container running an image from an ECR repository.

After doing the push commands to the repository, the image is updated successfully, however, the EC2 instance still runs the previous docker image.

I followed this documentation https://docs.aws.amazon.com/AmazonECS/latest/developerguide/update-service.html to update the Container Service and do a Force new deployment but no update when I visit the container URL.

Am I missing something in the process of deployment and updating a container image? Or probably I have to create a New Task Definition or re-run the current one?

UPDATE Going to my ECS service I see that the most recent deployment has 0 in the running count. Any way to update from here?

enter image description here


Solution

  • To update the image in the Service you can stop and re-run the task or restart the service.

    To restart a service:

    1. Log into the AWS Management Console.
    2. Go to Elastic Container Service.
    3. Go to Clusters.
    4. Click on the cluster that your service is in.
    5. Click on the service you’d like to restart.
    6. Click Update.
    7. Check Force new deployment about half way down the page.
    8. Click Skip to review.
    9. Click Update service.
    10. Wait patiently as your service restarts!

    Or with the cli:

    aws ecs update-service --cluster :clusterName --service :serviceName --force-new-deployment
    

    Credit where credit is due: https://joshtronic.com/2022/04/10/how-to-restart-an-aws-ecs-service/