Lesson 18 of 19 · 18m
Logs Fill Disks, Healthchecks Don't Restart Anything, and Restart Policies Have a Grammar
json-file logs grow unbounded by default, HEALTHCHECK reports status to nothing, and the four restart policies differ in exactly when they fire.
The default logging driver, json-file, writes every byte of stdout and stderr to /var/lib/docker/containers/<id>/<id>-json.log. Forever. There is no default rotation. The first time this matters is the night a chatty container fills the disk and takes the daemon — and everything else on the host — down with it.
json-file never rotates itself
Configure it before production learns it for you. Globally, in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}Per-container the same keys go in --log-opt or Compose's logging: block. Three 10 MB files is a 30 MB ceiling per container — bounded, boring, correct. The local driver does the same job with less overhead (~100 MB, block-structured). Pick journald if you already run systemd and want journalctl CONTAINER_NAME=web as your interface.
Know the retrieval limit: docker logs works only for json-file, local, and journald. Ship to fluentd, gelf, or syslog and logs leave the host — docker logs then answers "configured logging driver does not support reading," and your logs live in whatever you pointed at. Which is fine — that is what a real pipeline is — as long as nobody's runbook says docker logs first.
HEALTHCHECK reports. Nothing acts on the report.
HEALTHCHECK CMD curl -fs http://localhost/ || exit 1 — with --interval, --timeout, --start-period, --retries — makes docker ps print (healthy) or (unhealthy) and fills docker inspect -f '{{json .State.Health}}' with a log of recent check output. That is all it does. Plain Docker will not restart, replace, or remove an unhealthy container; health is metadata. Something has to consume it — Swarm's health-aware scheduling, autoheal-style watchers, your own supervisor — or the flag is decoration. Compose's depends_on: {db: {condition: service_healthy}} gates startup order only; it does nothing after the services are up.
Restart policies have a grammar
--restart takes four values with real semantic differences:
no— never restart. Default.on-failure[:N]— restart only on non-zero exit, at most N times. Zero exit means deliberate stop; Docker respects it.always— restart on any exit and after daemon restarts — including containers you stopped by hand, which surprises people after the daemon reboots.unless-stopped— restart on crash and daemon restart, but honor a manualdocker stop. The sane default for daemons you babysit.
docker update --restart unless-stopped web retrofits it without recreating. Exit code 137 means the kernel killed the process — check docker inspect for State.OOMKilled: true before blaming your app; that is the cgroup memory limit doing its job, the same limit the read-only-rootfs lesson set.
The events stream is the timeline
docker events --since 2h prints the lifecycle feed — create, start, die, kill, oom, health_status: unhealthy — as it happened. When a container disappears at odd hours, this is where the answer lives, alongside docker logs on the dead container (logs survive the exit; the writable layer survives too, until docker rm or prune eats it). docker inspect then gives State.ExitCode, FinishedAt, OOMKilled, Error — the postmortem in one object.
Try this
Run docker run -d --name noisy alpine sh -c 'while :; do echo x; done' and watch ls -lh /var/lib/docker/containers/*/. Now imagine a year of it. Kill it, then docker logs noisy — the evidence outlived the process.
Field notes
docker logs --since,--tail,-fcompose;--detailsadds the log-opt metadata.docker compose up -drecreates containers when the image digest or config changes — "the container restarted" is often "the container was replaced," anddocker eventsshows which.stop_grace_periodin Compose mirrorsdocker stop -t— default 10 seconds between SIGTERM and SIGKILL, same rule the PID 1 lesson covers.- A container with no HEALTHCHECK defined has no
State.Healthat all —docker inspectomits the field entirely. fluentd/gelf/syslogdrivers block container start when the endpoint is down unlessmode: non-blockingis set — a logging outage can take your deploy with it.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
What is Kubernetes? Container Orchestration at Scale
Kubernetes runs your Docker containers across a cluster of machines, handles scheduling, health checking, rolling deployments, auto-scaling, and self-healing. When your application outgrows a single server, Kubernetes is how it runs on ten.
What is Docker? Containers, Images, and Why Every Developer Needs to Know This
Docker packages your application and everything it needs to run into a container that behaves identically on your laptop, your teammate's machine, and the production server. "It works on my machine" stops being a problem. Here is how it actually works and what production usage looks like.