Image Tags

With Docker, a tag is a label that you can assign to a specific version of an image, similar to a tag in Git.

If you don’t explicitly supply a tag, Docker automatically applies the latest tag. However, latest does not magically mean it’s the newest version—it’s simply the default fallback string.

Semantic Versioning

It’s a best practice to use semantic versioning tags (like 0.1.0, 1.2.4) to keep track of different versions of your application.

Let’s say you update your code and want to publish version 0.2.0.

  1. Rebuild the image with the new tag:

    docker build . -t USERNAME/goserver:0.2.0
  2. Push the specific tag:

    docker push USERNAME/goserver:0.2.0

If you navigate to your repository on Docker Hub, you will now see two images with different tags (e.g., latest and 0.2.0).

Best Practices for “latest”

The convention is to use semantic versioning on all your images, but to also push to the latest tag for your most recent image. That way, you keep all of your old versions around for rollbacks, but the latest tag always points to the newest stable version.

For example, when releasing version 5.4.6:

# Tag the same build with both the specific version and 'latest'
docker build -t myusername/myapp:5.4.6 -t myusername/myapp:latest .

# Push all tags for this image
docker push myusername/myapp --all-tags