Naming, Tagging & Labeling Containers
Name containers, tag images, and use labels for metadata and automation hooks.
In plain words
Name running instances for operations, tag image releases for distribution, and label objects for queries and automation.
Think of it like…
Names are parking-space labels, tags are edition covers on a book, and labels are the catalog cards used to find and manage many books.
Where you’ve seen it
In practice, docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0 is the concrete move for this job: name containers, tag images, and use labels for metadata and automation hooks. The release is not accepted until docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue confirms the result.
Words you’ll hear
- --name
- The implementation control in
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0for name containers, tag images, and use labels for metadata and automation hooks. - Tags
- The result to observe with
docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue, rather than infer from a successful command alone. - Labels
- The production boundary exposed when assuming a semantic-version image tag identifies one particular running container forever.
Visual diagram
Theory & deep dive
--name control path
The concrete mechanism is docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0. The observable result is docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue; if those disagree, inspect the runtime evidence before changing unrelated settings.
Name containers, tag images, and use labels for metadata and automation hooks. Keep --name, Tags and Labels in the same deployment record so the intent and the observed state cannot drift apart.
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0
docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue, not with command success alone.Labels failure boundary
Mixing these concepts creates dangerous cleanup and deployment scripts. Runtime names are local to a daemon, tags can move, and labels are the stable metadata hooks that can carry owner, version, commit or policy information. The narrow failure to design for is assuming a semantic-version image tag identifies one particular running container forever.
Accept this compromise explicitly: Human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse. The controlled check-docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue-also identifies the point where a different design is safer.
Exercise this failure safely: assuming a semantic-version image tag identifies one particular running container forever.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Mixing these concepts creates dangerous cleanup and deployment scripts. Runtime names are local to a daemon, tags can move, and labels are the stable metadata hooks that can carry owner, version, commit or policy information.
- Intent
- --name
When to use it & trade-offs
What it is
A container name is a unique runtime handle, an image tag is a mutable registry reference, and a label is key/value metadata attached to an image or container. Those namespaces are different: app:2.1 may become several containers named app-blue and app-green.
Why it matters: Mixing these concepts creates dangerous cleanup and deployment scripts. Runtime names are local to a daemon, tags can move, and labels are the stable metadata hooks that can carry owner, version, commit or policy information.
When to reach for it
- The fit is strongest for this job: name containers, tag images, and use labels for metadata and automation hooks. Pair it with
docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-bluein the runbook. - Production --name changes should make Tags observable through
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0, rather than trusting the runtime default. - Keep a rollback example for the case where assuming a semantic-version image tag identifies one particular running container forever.
When to avoid or be careful
- Do not accept command success while the system can still fail by assuming a semantic-version image tag identifies one particular running container forever.
- Avoid erasing Labels protection merely to dodge this cost: “Human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse”.
- Do not replace the evidence path-
docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue-with a screenshot or a mutable tag.
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0: practical choices
Strengths: A container name is a unique runtime handle, an image tag is a mutable registry reference, and a label is key/value metadata attached to an image or container. Those namespaces are different: app:2.1 may become several containers named app-blue and app-green.
Watch out: Human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse.
Strengths: It can begin with docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0 and fewer surrounding controls.
Watch out: It silently accepts assuming a semantic-version image tag identifies one particular running container forever, which makes the result hard to reproduce after promotion.
Strengths: Mixing these concepts creates dangerous cleanup and deployment scripts. Runtime names are local to a daemon, tags can move, and labels are the stable metadata hooks that can carry owner, version, commit or policy information.
Watch out: The platform adds an ownership and debugging layer; retain docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0
- docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue
- Failure signature: assuming a semantic-version image tag identifies one particular running container forever
- Trade-off: Human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse.
Benchmarks & rules of thumb
- 1 unique runtime name
- per Docker daemon
- 128 characters
- maximum image-tag length
- 2 identities
- a mutable tag and an immutable running container ID are not interchangeable
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0as proof and skippingdocker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue. - Assuming a semantic-version image tag identifies one particular running container forever
- Optimizing --name without accepting that human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse.
Likely interviewer follow-ups
- Why does
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0address --name here rather than through application code? - How would you distinguish healthy Tags from the failure “assuming a semantic-version image tag identifies one particular running container forever” using
docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue? - When would this trade-off-“Human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse”-justify a different Labels design?
docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0-and one proof-docker ps --filter label=org.acme.owner=payments and docker inspect --format {{index .Config.Labels "org.opencontainers.image.revision"}} api-blue. Then name the boundary: assuming a semantic-version image tag identifies one particular running container forever.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Naming, Tagging & Labeling Containers with generative AI interview Q&A and hands-on practice.