Reputation: 2597
I have an aws ec2 cluster with a service that runs a task. Let's say the task's image is my-app:latest
When I want to update the application I build a new docker image and push it to the ECR.
Now, how do I roll the new my-app:latest
image to my instances?
Upvotes: 1
Views: 249
Reputation: 59966
Updating the Docker image involves two approaches
First one, only update docker image and push to ECR without modifying the tag that isaws.abc/myimage:latest
, so, in this case, you do not need to update the task definition you just need to redeploy the service. you can do from AWS console or from aws cli
aws ecs update-service --cluster ec2cluster_name --service service_name --force-new-deployment
This all you need,
The second one, if you use different docker image tag then you also need to update task definition that will point to the new Docker image and redeploy the service.
Register new version of the task definition
Now specify the task definition revision. rest of the thing will be the same except the docker image tag.
{
"containerDefinitions": [
{
"cpu": 0,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/stage-app",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "ecs"
}
},
"environment": [
{
"name": "BRANCH",
"value":"staging"
},
{
"name": "NODE_ENV",
"value": "staging"
}
],
"memoryReservation": 400,
"ulimits": [
{
"name": "nofile",
"softLimit": 4000,
"hardLimit": 4000
}
],
"image": "***.dkr.ecr.us-west-2.amazonaws.com/stage:stage",
"dockerLabels": {
"Name": "stage-app"
},
"privileged": true,
"name": "stage-app"
}
],
"family": "stage-app"
}
Register this revision
aws ecs register-task-definition --cli-input-json file://stage-nodejs.json
update the service with the new task definition
aws ecs update-service --cluster cluster_name --service service_name --task-definition task_definition_name
redeploy the service
aws ecs update-service --cluster ec2cluster_name --service service_name --force-new-deployment
Upvotes: 2