Lesson 29 of 30
`docker stats` answers 'is this one container healthy right now' — and stops being a usable answer the moment you have more containers than fit on one terminal screen. What replaces it is the same aggregation problem logging has, applied to CPU, memory, and I/O.
11 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
`docker stats` works well for checking one container's resource usage during local debugging. Why does it stop being a usable tool for a fleet of 200 containers across 15 machines?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Metrics are numeric measurements sampled over time — CPU percent, memory usage, network I/O, disk I/O — as opposed to the discrete event records logging deals with. The resource-limits lesson in this track covers setting cgroup-enforced CPU/memory limits; this lesson is about observing what a container is actually using against those limits, and noticing it's approaching them before it gets OOM-killed rather than after.
docker stats is the direct, manual answer: a live terminal view of CPU%, memory usage/limit, network I/O, and block I/O for running containers on the current host. It's genuinely useful for a quick "is this one container behaving" check during local debugging — and it stops scaling almost immediately past that. It shows only the current host, only currently-running containers, only right now, with no history and no alerting. A fleet of 200 containers across 15 machines has no meaningful docker stats story at all.
cAdvisor (Container Advisor) is the piece that generalizes this: an agent that runs on each host, collecting the same category of per-container resource metrics docker stats shows, but exposing them in a form built for aggregation rather than a live terminal view. An orchestrator's own built-in metrics (Kubernetes' metrics-server, and similar) do an equivalent job, often using cAdvisor internally. Either way, the typical next step is the same: those metrics get scraped by Prometheus (a time-series metrics database built for exactly this kind of periodic scraping and storage) and visualized in Grafana (dashboards and alerting on top of that stored data) — the standard stack for "resource metrics across a whole fleet, queryable and alertable, not just visible one host at a time."
# manual, one host, right now
docker stats --no-stream
# CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O
# api-1 340% 980MiB / 1GiB 95.7% 1.2MB / 800kB
That single row is the whole story docker stats can tell — a memory usage sitting at 95.7% of its limit, one step from an OOM-kill, visible only because someone happened to be watching this terminal at this moment. The aggregated version of the same fact — cAdvisor scraped by Prometheus, graphed and alerted on in Grafana — turns that "someone happened to notice" into "an alert fires automatically when any container in the fleet crosses a memory threshold," which is the actual point: metrics exist so you find out before the OOM-kill, not from its aftermath in the logs.
docker stats has no history. It shows the current instant only — if a container spiked to 100% CPU for thirty seconds five minutes ago and you weren't watching, that data is simply gone, which is precisely the gap a time-series store like Prometheus is built to close."A container keeps getting killed in production and we don't know why" is a real incident-response scenario, and a strong answer routes through metrics history (was memory climbing before the kill, was it CPU throttling) rather than only checking logs after the fact — naming cAdvisor/Prometheus/Grafana as the standard fleet-wide answer, and docker stats as its useful-but-limited single-host precursor, shows the difference between debugging one container and operating a fleet of them.