2

Ideal scenario:

I create a new tag for an existing docker hub repo:

docker build . -t org/repo:v1

I have a docker-compose that reads that tag:

version: '2'
services:
  api:
    image: org/repo
    ...

However, this does not work because there's no tag of latest.

Is there a way to get this behavior? Otherwise, every deploy has to modify the docker-compose.yml which seems stupid.

I have a solution that is ugly but it works: I simply have to retag and push a latest tag.

docker tag org/repo:v1 org/repo:latest
docker push org/repo:latest

Any better ideas?

user3162553
  • 2,699
  • 3
  • 37
  • 61

1 Answers1

3

See "The misunderstood Docker tag: latest" from Marc Campbell: latest is a tag referencing a tag pushed:

Latest is just a tag with a special name.

It doesn’t mean anything special unless you use a pretty specific build/tag/push/pull/run pattern.

“Latest” simply means “the last build/tag that ran without a specific tag/version specified”.

In other words, you could build new versions like this:

sudo docker build -t marc/test .
sudo docker tag marc/test marc/test:2 
...
sudo docker build -t marc/test .
sudo docker tag marc/test:3
...

But this is a little odd. Why would I have to tag everything twice?

If you are shipping Docker images to a production environment, you should just ignore the latest tag.
Don’t use it. Don’t be tempted by it.
It’s easy to look at it and think that your deployment script should just pull “latest” and your build process will ensure that’s valid. It takes a lot of discipline to make that work. Just version your tags. Every time.

See more with "Docker: The latest Confusion" from Adrian Mouat:

If the repository is to be uploaded to the Docker Hub, the repository name must be prefixed with a slash and the Docker Hub user name e.g. amouat/myrepo:mytag.

The trick is of course, if you leave the tag part out (e.g. docker tag myrepo:1.0 myrepo), Docker will automatically give it the tag latest.

See "How to create named and latest tag in Docker?".

Just because an image is tagged latest, does not mean that it is the most up-to-date image within its repository.

So what happens if you do the pull on a repository with no latest tag?
This:

$ docker pull amouat/myrepo
Pulling repository amouat/myrepo
2015/01/21 12:04:06 Tag latest not found in repository amouat/myrepo

The OP adds:

The issue I had is trying to keep the dev environment synced with latest changes without having to manually edit the docker-compose.yml with the new tag every change.

For that, I always maintain a "deployed" tag which is shifting (applied only when I upgrade an image tag) and used in scripts/docker-compose.yml.

I prefer building my own image in order to add LABELs which are used to memorize what that "deployed" tag actually refers to (I setup a LABEL named "tag" with the actual tag name in it).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you! I think the approach then is to avoid using the repo in development in the `docker-compose.yml` and instead reference the remote repository in production deploys. The issue I had is trying to keep the dev environment synced with latest changes without having to manually edit the `docker-compose.yml` with the new tag every change. – user3162553 May 20 '18 at 00:32
  • @user3162553 I have edited my answer to address your comment. – VonC May 20 '18 at 00:56