Docker container names and IDs
Quick answer
A container ID identifies a specific container. A name is a more readable identifier that must be unique on its engine. Most container commands accept either an existing name or a full ID; a sufficiently unique ID prefix also works.
Before you run commands
Use an approved disposable Linux-container Docker lab. Confirm the effective context and permissions; use a reviewed, locally preloaded busybox:1.37 image whose digest/platform the lab owner has recorded. This tag is mutable. Do not download an image automatically; --pull=never requires it locally. The new containers use --network none, with no host mounts or published ports; the CLI still connects to the selected engine. Verify the approved image tag still resolves to the recorded image before creating containers. Check docker ps -a for all names used below. If any is occupied, choose fresh names consistently. Run commands one at a time and stop on any unexpected failure; never act on resources you did not create. Expected results are predictions, not measured execution.
How it works
Two containers may share an image but have separate identities. In this example both are created without running. docker inspect --format selects one field from the container metadata. The expression in quotes is a formatting template, not a shell variable. .Id selects the full ID and .State.Status selects the state. Use docker ps -a to locate names and shortened IDs. Stopped containers still reserve their names.
docker create --pull=never --network none --name bm02-id-a busybox:1.37 echo Adocker create --pull=never --network none --name bm02-id-b busybox:1.37 echo Bdocker container inspect --format '{{.Id}} {{.State.Status}}' bm02-id-a bm02-id-bdocker ps -a# Match the ID prefixes before cleanup.docker rm bm02-id-a bm02-id-bExpect two different full IDs and created for both. Do not copy IDs from someone else’s output.
Common mistake
A container name is not an image name. Use the name you actually created when stopping or removing it. Avoid broad selection and full metadata dumps, which can expose unrelated resources or environment values.
Try it yourself
Pause before the cleanup line. Match both rows in docker ps -a to the full IDs printed by inspect; then remove only these two newly created containers. Explain why the IDs differ.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker container names and IDs — knowledge check
Apply the lifecycle concepts and interpret the lab behavior.
Two containers use the same image. What is true?
Can a stopped container reserve its name?
Which output field gives the full container ID in the example?