Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 11/ 160
01. Containerization & Docker Fundamentals

Viewing Container Logs & Debugging (docker logs, inspect, stats)

Use logs, inspect, and stats to diagnose crashes, resource spikes, and misconfig.

Beginnerlogs · inspect3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Read the exit evidence and logs first, then correlate state and live resource counters.

Think of it like…

Logs are the cockpit voice recorder, inspect is the maintenance report, and stats is the live set of gauges.

Where you’ve seen it

In practice, docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api is the concrete move for this job: use logs, inspect, and stats to diagnose crashes, resource spikes, and misconfig. The release is not accepted until correlate the 10-minute log timeline with container state and a one-shot resource sample confirms the result.

Words you’ll hear

logs
The implementation control in docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api for use logs, inspect, and stats to diagnose crashes, resource spikes, and misconfig.
inspect
The result to observe with correlate the 10-minute log timeline with container state and a one-shot resource sample, rather than infer from a successful command alone.
stats
The production boundary exposed when mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window.

Visual diagram

Loading interactive diagram

Theory & deep dive

logs control path

The concrete mechanism is docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api. The observable result is correlate the 10-minute log timeline with container state and a one-shot resource sample; if those disagree, inspect the runtime evidence before changing unrelated settings.

Use logs, inspect, and stats to diagnose crashes, resource spikes, and misconfig. Keep logs, inspect and stats in the same deployment record so the intent and the observed state cannot drift apart.

Concrete logs setup

docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api

Key takeaway: Prove inspect with correlate the 10-minute log timeline with container state and a one-shot resource sample, not with command success alone.

stats failure boundary

Starting another copy before collecting State.Error, OOMKilled and exit code destroys the clearest signal. The log command can also fail or be incomplete with non-json drivers, so observability should not depend on a single CLI path. The narrow failure to design for is mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window.

Accept this compromise explicitly: CLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services. The controlled check-correlate the 10-minute log timeline with container state and a one-shot resource sample-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window.

Key takeaway: CLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Starting another copy before collecting State.Error, OOMKilled and exit code destroys the clearest signal. The log command can also fail or be incomplete with non-json drivers, so observability should not depend on a single CLI path.

Read the exit evidence and logs first, then correlate state and live resource counters.
Key numbers at this step
Intent
logs

When to use it & trade-offs

What it is

docker logs reads the stdout/stderr stream captured by the configured logging driver, docker inspect supplies state, environment and error details, and docker stats samples CPU, memory, block I/O and network counters from the runtime. Together they distinguish an app crash from resource pressure or bad configuration.

Why it matters: Starting another copy before collecting State.Error, OOMKilled and exit code destroys the clearest signal. The log command can also fail or be incomplete with non-json drivers, so observability should not depend on a single CLI path.

When to reach for it

  • The fit is strongest for this job: use logs, inspect, and stats to diagnose crashes, resource spikes, and misconfig. Pair it with correlate the 10-minute log timeline with container state and a one-shot resource sample in the runbook.
  • Production logs changes should make inspect observable through docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api, rather than trusting the runtime default.
  • Keep a rollback example for the case where mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window.

When to avoid or be careful

  • Do not accept command success while the system can still fail by mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window.
  • Avoid erasing stats protection merely to dodge this cost: “CLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services”.
  • Do not replace the evidence path-correlate the 10-minute log timeline with container state and a one-shot resource sample-with a screenshot or a mutable tag.

docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api: practical choices

Explicit logs
Best for: Use logs, inspect, and stats to diagnose crashes, resource spikes, and misconfig, with a reviewed runbook.

Strengths: docker logs reads the stdout/stderr stream captured by the configured logging driver, docker inspect supplies state, environment and error details, and docker stats samples CPU, memory, block I/O and network counters from the runtime. Together they distinguish an app crash from resource pressure or bad configuration.

Watch out: CLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services.

Ambient default
Best for: Short-lived inspect experiments with low blast radius.

Strengths: It can begin with docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api and fewer surrounding controls.

Watch out: It silently accepts mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window, which makes the result hard to reproduce after promotion.

Managed stats
Best for: Teams that centralize stats policy across many workloads.

Strengths: Starting another copy before collecting State.Error, OOMKilled and exit code destroys the clearest signal. The log command can also fail or be incomplete with non-json drivers, so observability should not depend on a single CLI path.

Watch out: The platform adds an ownership and debugging layer; retain correlate the 10-minute log timeline with container state and a one-shot resource sample as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api
  • correlate the 10-minute log timeline with container state and a one-shot resource sample
  • Failure signature: mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window
  • Trade-off: CLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services.

Benchmarks & rules of thumb

137 -
128 plus SIGKILL, commonly an OOM kill
143 -
128 plus SIGTERM, commonly a graceful-stop timeout
10 minutes -
a focused recent log window for triage

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api as proof and skipping correlate the 10-minute log timeline with container state and a one-shot resource sample.
  • Mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window
  • Optimizing logs without accepting that cLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services.

Likely interviewer follow-ups

  • Why does docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api address logs here rather than through application code?
  • How would you distinguish healthy inspect from the failure “mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window” using correlate the 10-minute log timeline with container state and a one-shot resource sample?
  • When would this trade-off-“CLI inspection is immediate during an incident; a metrics/log backend preserves history and allows correlation across many services”-justify a different stats design?
Interview tip: Give one concrete operation-docker logs --since 10m --timestamps api; docker inspect -f {{.State.ExitCode}}:{{.State.OOMKilled}} api; docker stats --no-stream api-and one proof-correlate the 10-minute log timeline with container state and a one-shot resource sample. Then name the boundary: mistaking an exit code 137 for an application bug without checking memory events, or relying on logs after rotation has removed the needed window.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Viewing Container Logs & Debugging (docker logs, inspect, stats) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Executing Commands Inside Running Containers (docker exec, attach)
Next topic
Port Mapping & Exposing Services (-p, -P)