Basic

Reading a version string

Every image and every package carries a version string, and the string is the contract. Semantic versioning says the first number is the breaking one: 2.0.0 is not a newer 1.9.9, it is a different major that may break callers. Learn to read it before you learn to write one.

What you will see

Tags include `latest` if you used it. `latest` is a pointer that changes when you rebuild; a numbered tag does not.

About 1 min of reading

Try It

Compare versions the wrong way, then the right way

1

See the string bug

python -c "print('1.10.0' > '1.9.0')"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
False. Text comparison puts 9 before 10 because it compares character by character.
2

Install the comparator

pip install packaging

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The packaging package is installed; it is part of the standard Python tooling ecosystem.
3

Compare numerically

python -c "from packaging.version import Version as V; print(V('1.10.0') > V('1.9.0'))"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
True. Each component is compared as a number.
4

Spot a moving label

docker images --format '{{.Tag}}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Tags include `latest` if you used it. `latest` is a pointer that changes when you rebuild; a numbered tag does not.
Do not delete `latest` from a registry you depend on; instead stop depending on it by pinning a number.

Data Flow

Version string to a decision
1 Read the string from a manifest or tag
↓
2 Parse into numeric components
↓
3 Compare per component, not as text
↓
4 Decide: accept, test, or reject
Why this works
Why the first number matters

A major bump is a promise that the interface may have changed. If your code survived 1.9.9 and 2.0.0 fails, that is the contract working as designed. If it silently misbehaves, you depended on something the version string did not promise.

Where version strings come from

Package managers, image tags, and API headers all carry them. The discipline is the same everywhere: compare numerically, pin explicitly, and treat a moving label as a convenience, not a dependency.

Examples

major.minor.patch

1.4.2 means: first number is the breaking axis, second is additive features, third is bug fixes. A consumer that pins 1.4.x can accept 1.4.9 without a test. It must not accept 2.0.0 without one.

Pre-release suffixes

1.4.0-rc1 sorts before 1.4.0. Docker image tags use the same ordering idea: v1:latest is a moving pointer, v1:v1.4.2 is a fixed one. Never depend on a moving pointer in code that must be reproducible.

Compare with a library, not a string

'1.10.0' > '1.9.0' is False in Python string comparison. Use packaging.version or the equivalent in your language so the comparison is numeric per component.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← What a container actually is
Previous Lesson
What a container actually is
Next Lesson
Tags, layers, and the cache
Tags, layers, and the cache →