Inspect a container after it exits
Quick answer
A container can exist after its main process exits. docker ps normally lists running containers, while docker ps -a includes stopped containers. This lesson makes one temporary named container so you can examine the difference.
Create a container without automatic cleanup
Use the same approved lab and preloaded image as the previous lesson. Check the effective context before sending commands. First list all containers. If bytemind-docker-intro exists, use a fresh name consistently. Run the greeting image without --rm; continue only if this creation succeeds. Never remove an unrelated container.
docker ps -a# Continue only if the lab name is unused.docker run --pull=never --network none --name bytemind-docker-intro hello-world:latestInspect and clean up
After the program finishes successfully, its container should appear in the all-containers list with an exited status, not in the running-only list. docker logs reads the captured output for this container using the normal lab logging configuration. docker rm removes the stopped container and its writable layer, not its image. Only remove the container you created in this lab. The exact IDs and timestamps vary. Run each command separately; stop if anything unexpected happens. The first list omits the completed job, the second includes it. If the logging configuration cannot return captured output, record that limitation rather than assuming the job did not run.
docker psdocker ps -adocker logs bytemind-docker-introdocker rm bytemind-docker-introdocker ps -aTry it yourself
Before cleanup, identify the named stopped container and its logs. After cleanup, check that this container no longer appears in the all-containers list.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inspect a container after it exits — knowledge check
Check understanding of the lesson concepts.
After a named greeting job finishes, which Docker CLI command still lists that exited container?
What happens when you remove the stopped lab container?