Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 14/ 160
01. Containerization & Docker Fundamentals

Naming, Tagging & Labeling Containers

Name containers, tag images, and use labels for metadata and automation hooks.

Beginner--name · Tags3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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.0 for 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

Loading interactive 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.

Concrete --name setup

docker run -d --name api-blue --label org.acme.owner=payments --label org.opencontainers.image.revision=$GIT_SHA api:2.1.0

Key takeaway: Prove Tags with 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.

Deliberate failure test

Exercise this failure safely: assuming a semantic-version image tag identifies one particular running container forever.

Key takeaway: Human-readable names help incidents, but scripts should prefer labels, digests and IDs because names are easy to reuse.

How it works, step by step

Step 1 of 4
Design

1. 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.

Name running instances for operations, tag image releases for distribution, and label objects for queries and automation.
Key numbers at this step
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-blue in 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

Explicit --name
Best for: Name containers, tag images, and use labels for metadata and automation hooks, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Tags experiments with low blast radius.

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.

Managed Labels
Best for: Teams that centralize Labels policy across many workloads.

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.0 as proof and skipping docker 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.0 address --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?
Interview tip: Give one concrete operation-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

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Naming, Tagging & Labeling Containers with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Managing Environment Variables (-e, --env-file)
Next topic
Restart Policies (no, always, unless-stopped, on-failure)