Docker debugging: logs, processes and resource snapshots
Start with evidence
A container that seems broken may be stopped, running but quiet, or running with an application problem. Check its lifecycle before opening an extra shell. Logs show messages, top shows active processes and stats reports resource observations. Each answers a different question.
Lab prerequisites
Use an approved disposable Linux-container lab only. Verify the active context (docker context show), CLI/daemon versions and that the instructor has reviewed and preloaded the BusyBox 1.37 fixture for the target platform; record its digest before use. The tag is inherited from earlier chapters, not a verified immutable identity. --pull=never avoids automatic downloads; --network none isolates normal network access for these local-only tasks. Verify each bm-v04 name is unused; if not, choose a fresh name consistently. Run host commands one at a time in Bash, stop on unexpected errors, and clean up only the container you created. If a fixture times out, inspect its state before retrying; remove only your stopped fixture. All snippets are static, not executed by ByteMind. Before any engine request, confirm the effective approved daemon endpoint, including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides; do this privately in each terminal. Confirm the local tag still resolves to the approved image identity and platform. If any check fails, use the paper exercise instead. The network flag limits container networking, not the client-to-daemon connection. Use a lab with readable, local-only logging and an owner-set execution time limit; confirm your fixture identity before every cleanup.
Investigate a quiet fixture
The fixture writes one message and waits for 300 seconds. Expect state running, the message worker started and a process listing that includes the fixture’s waiting command. Resource figures and process IDs vary by host and time. --no-stream requests a single snapshot instead of continuous display. If a check fails, read the actual error and do not escalate privileges.
docker run -d --pull=never --network none --name bm-v04-debug busybox:1.37 sh -c 'echo worker started; sleep 300'docker container inspect --format '{{.State.Status}}' bm-v04-debugdocker logs --tail 5 bm-v04-debugdocker top bm-v04-debugdocker stats --no-stream bm-v04-debugdocker stop bm-v04-debugdocker rm bm-v04-debugDiagnose an exited fixture
This separate fixture prints a synthetic message to standard error and returns exit code 7. The nonzero result from the first command is intentional; continue to the diagnostic commands, which should show exited 7 and the message. The application exit code is not a diagnosis by itself. Here the cause is known because we wrote the fixture. Capture the first command’s exit status immediately. Continue only when it is the intentional 7 and the container is the fixture you created. A failed Docker launch is not the application’s failure.
docker run --pull=never --network none --name bm-v04-failure busybox:1.37 sh -c 'echo demo failure >&2; exit 7'printf 'Run exit status: %s\n' "$?"# Continue only after verifying the intentional exit 7 and fixture ownership.docker container inspect --format '{{.State.Status}} {{.State.ExitCode}}' bm-v04-failuredocker logs bm-v04-failuredocker rm bm-v04-failureChoose the least disruptive check
For a stopped container, inspect and available logs are often more useful than exec. For a running container with high CPU, take repeated measurements before drawing conclusions; one sample is not a benchmark. Never fix an unexplained problem by removing every container or disabling security settings. Record observations, hypothesis, correction and verification.
Manual practice
On paper, select the first useful checks for a container that exits quickly, a quiet running worker and a worker suspected of high memory use. For each, write what the evidence can establish and one question it cannot answer.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker debugging: logs, processes and resource snapshots — Knowledge check
Apply the concepts from this lesson.
Which pair is useful when a container has already exited?
Which command gives a resource snapshot rather than a continuous display?
What can one high CPU snapshot of the selected running container establish?