Pavel Bernshtam
Pavel Bernshtam

Reputation: 4444

How to manage versions of docker image in AWS ECS?

AWS ECS service points to a Task Definition, which holds a name of docker image, including a tag.

So when I create a new version of my docker image I have 2 possibilities:

  1. Update Task definition to the new version and then update Service to point to the new revision of Task Definition
  2. Use some tag to point to the last version, let's say "current" tag will always point to the last version, Task Definition will contain "my-image:current" and then I need just restart ECS service

What is better and why?

Upvotes: 2

Views: 2192

Answers (1)

David Maze
David Maze

Reputation: 160013

Use a unique tag for every build, and update the task definition to point at the new tag (your first option).

The big problem you'll run into is that, in general, Docker-based systems will try to avoid pulling an image they already have. If you restart the service, but the node it restarts on sees it already has my-image:current, it will just re-run it without pulling the updated version. It seems like it can work – How does "latest" tag work in an ECS task definition and container instances pulling from ECR? includes a setup which appears to work – but it's a little hard to tell just from looking at things what exact version you have in use.

A second good reason to avoid a "current" or "latest" tag is to have the ability to roll back. If you use, for example, a timestamp-based tagging system, you deploy build 20200323, and it doesn't work, it's very easy to reset the task definition back to build 20200322 to get back to yesterday's code while your developers debug things. If it was "current" yesterday, and it's "current" today, it's a lot harder to figure out what "not-current" should be.

Upvotes: 4

Related Questions