The common-bugs field reference names five specific failure modes and their fixes. This lesson is the actual toolkit for finding out which one you're looking at in the first place — the handful of commands that turn "the container is being weird" into a specific, diagnosable fact.
3 min read
A container's isolation (its own filesystem view, its own process namespace) doesn't mean it's a black box to the host it's running on — a small set of Docker commands can inspect a running container's state, resource usage, and logs without needing the application itself to expose any special debugging endpoint.
docker logs: the first, obvious stepdocker logs my-container
docker logs -f my-container # follow, like tail -f
docker logs --since=10m my-containerThe container's stdout/stderr, captured by Docker regardless of whether the application writes to a file. This is the starting point for almost every investigation — and its absence of useful output (an OOM-killed process leaves nothing here, exactly as the resource-limits lesson described) is itself a diagnostic signal, not a dead end.
docker exec: getting an actual shell inside a running containerdocker exec -it my-container /bin/shThis runs a new process inside the container's existing namespaces —
not a separate container, the same isolated environment the application
is actually running in. From here, ordinary tools (checking environment
variables, testing DNS resolution to another service, confirming a
config file's actual contents on disk) work exactly as they would
debugging any Linux process, just scoped to what that container can see.
A minimal or distroless image (from the image-security lesson) has no
shell at all, trading this convenience away for a smaller attack surface —
worth knowing before reaching for exec on one and getting nothing back.
docker stats: live resource usagedocker stats my-containerCONTAINER CPU % MEM USAGE / LIMIT MEM %
my-container 145.2% 498MiB / 512MiB 97.3%
This is the direct, live view into whether a container is actually
hitting the resource limits described in the previous lesson — a memory
percentage sitting near 100% is a container about to be OOM-killed, and
CPU usage pinned near its --cpus ceiling is a container being throttled,
both confirmable here before (or instead of) guessing from application
symptoms alone.
docker inspect: the full configuration and state, as JSONdocker inspect my-container --format='{{.State.OOMKilled}}'
docker inspect my-container --format='{{.State.ExitCode}}'
docker inspect my-container --format='{{json .Config.Env}}'inspect returns a container's complete metadata — its exact resource
limits, environment variables, mounted volumes, network settings, and
detailed exit/health state — as structured JSON, filterable with
--format to pull out exactly one field instead of scrolling a large
dump. This is precisely the command the common-bugs lesson uses to
confirm OOMKilled: true as a specific, checkable fact rather than an
inference from symptoms.
docker top: what's actually running inside, right nowdocker top my-containerLists the processes running inside a container's process namespace,
directly from the host — useful for confirming a container's PID 1 is
actually the application process and not an unexpected shell wrapper (the
SIGTERM-ignored bug from the common-bugs lesson traces to exactly this
kind of mismatch), or for spotting an unexpected zombie or runaway
process without needing a shell inside the container at all.
Rather than guessing which of the common-bugs lesson's five scenarios applies, this sequence — logs, then inspect, then stats or exec depending on what inspect reveals — turns "something's wrong" into a specific, evidence-backed diagnosis in a handful of commands, before touching any application code at all.
Check your understanding
A quick comprehension check — not tracked, not graded, just for you.
1. Why does docker exec work on a minimal image but not on a distroless one?
2. What can docker inspect --format='{{.State.OOMKilled}}' confirm that docker logs alone cannot?
3. What does docker stats show that helps confirm a resource-limit-related problem?
4. How does docker top help diagnose the SIGTERM-ignored bug from the common-bugs lesson?
Docker & Containers