Latest tag

2 snippets across 2 stacks - Docker, Git

DKDocker

Not Pinning Image Versions

DK · Common Mistakes
Syntax
# Problem:
FROM node:latest
FROM python
FROM nginx
Example
# Fix - pin to specific versions:
FROM node:20.11.1-alpine3.19
FROM python:3.12.2-slim-bookworm
FROM nginx:1.25.4-alpine

Note An image tag like :latest or :20 can change at any time. Your build might work today and fail tomorrow because the base image was updated. In CI, a non-reproducible build means you cannot investigate a production issue with the exact same image.

GitGit

Find the Latest Tag

Git · Tags
Syntax
git describe --tags --abbrev=0
git describe --tags
Example
git describe --tags --abbrev=0
git describe --tags
Output
v2.0.0
v2.0.0-3-ga1b2c3d

Note --abbrev=0 gives just the tag name. Without it, Git also shows how many commits since that tag and the current abbreviated hash. Useful in CI/CD for version stamping.

Frequently asked questions

How does Docker handle latest tag?
This task is covered in 2 stacks on this page: Docker, Git. The "Not Pinning Image Versions" snippet in Docker uses `# Problem:`.
Which command does the Docker example use?
The "Not Pinning Image Versions" snippet uses `# Problem:`, from the Common Mistakes section of the Docker cheat sheet.
Which stacks cover "latest tag" on this page?
Docker, Git. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Not Pinning Image Versions": An image tag like :latest or :20 can change at any time. Your build might work today and fail tomorrow because the base image was updated. In CI, a non-reproducible build means you cannot investigate a production issue with the exact same image.