Images, containers, names, and state
Know the difference between an image, a container, and a running process.
docker ps
20 min read, 25 min lab
operator
An image is a template. A container is a created runtime instance. `docker ps` shows running containers; `docker ps -a` includes stopped ones. Names, ports, and status are the first facts to capture.
A local service is not responding and you need to know whether the container is running.
Worked command
$ docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'$ docker ps -a$ docker inspect web
Do not rebuild before checking whether the container is stopped, unhealthy, or unbound from the expected port.
Record name, image, status, ports, and health first.
Your service is unreachable and `docker ps` shows nothing for it. What is the most likely reason, and the right next command?
Show the answer
Correct: B. The container is stopped or exited; run docker ps -a to see it
docker ps lists only running containers, so a stopped or exited container is hidden until you add -a. The trap is jumping to docker build, which assumes the image is gone and rebuilds before you have even confirmed the container exists.
Practice checklist
- Use a disposable container or sample output.
- List running and stopped containers.
- Identify name, status, and ports.
Deliverable evidence
- Container inventory table.
- A note explaining image vs container.
shows: The outside-in debugging order — ps, logs, ports/mounts, then exec only on a hypothesis — plus the Compose lifecycle from down (keeps named volumes) to down --volumes (destroys them).
does not prove: The order tells you where to look, not what is wrong; a clean log and a present port mapping narrow the cause but do not by themselves prove the service is healthy.
Commit these to memory, then drill them until recall is automatic.
cue Show stopped and exited containers, not just running ones
show recall target
docker ps -a