Self-Hosting · Reliability
Docker Hardening for Home Servers: Resource Limits, Healthchecks and Restart Policies
A default Compose file trusts every container completely: unlimited memory, unlimited CPU, restart forever or never, logs without end. On a home server that trust is how one leaking container fills the disk with logs or eats all the RAM and takes the house’s services down with it. This guide covers the six settings that change that — all plain Compose, no extra tooling — and which values make sense at home.
Published Nov 20, 2026
Memory and CPU limits: the seatbelts
Without limits, a container can consume the host’s entire RAM, at which point the kernel starts killing processes to survive — and it does not consult you about which ones. Set a ceiling per service with the Compose v2 resource syntax:
deploy:
resources:
limits:
memory: 512M
cpus: "1.5"
Sizing rule: watch the container’s real usage for a week (Docker stats, or Beszel from our monitoring guide), then set the limit at roughly double its normal peak. Media servers and Immich’s machine-learning container legitimately want more; most web apps live happily in 256–512 MB. A limit that occasionally bites is still better than no limit: the container restarts instead of the host falling over.
Healthchecks: how a restart policy knows
restart: unless-stopped only helps when a container exits. The nastier failure is a process that stays up but stops working — a wedged web server accepting no connections. A healthcheck closes that gap: Docker runs a probe inside the container on an interval and marks it healthy or unhealthy, which your monitoring can alert on and your stack can order around with depends_on: condition: service_healthy.
healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/health"] interval: 30s timeout: 5s retries: 3 start_period: 40s
Use the application’s own health endpoint when it has one; otherwise check its port or a lightweight command it ships (many images include wget or a CLI status command). The start_period matters: it gives slow starters (databases, Java apps) a grace window where failed probes don’t count. Prioritize healthchecks for the infrastructure containers — databases, reverse proxies — whose silent failure cascades.
Restart policies, chosen deliberately
Four options, four meanings. no: never restart — right for one-shot jobs. on-failure: restart only on a non-zero exit, optionally with a retry cap — right for fragile workers. always: restart even if you stopped it manually, which surprises people after maintenance. unless-stopped: restart after crashes and host reboots, but respect a manual stop — the right default for nearly every home service. If you find a container in a crash loop, the policy is doing its job of keeping it available; fix the cause, and let our update strategy keep you off the bad version that started it.
Read-only, unprivileged, and dropped capabilities
Three settings shrink what a compromised container can do. read_only: true makes the container’s filesystem immutable (pair it with tmpfs mounts for the scratch paths the app genuinely needs — test before deploying widely, some apps assume a writable filesystem in odd places). security_opt: ["no-new-privileges:true"] blocks privilege escalation inside the container and is safe for almost everything. cap_drop: ["ALL"] removes Linux capabilities, adding back only specific ones a container truly needs (NET_ADMIN for VPN containers like Gluetun is the common exception). Apply them one container at a time and watch the logs; a service that runs fine hardened for a week will run that way forever.
Log rotation: the quiet disk-filler
Docker’s default json-file log driver has no size limit. A chatty or error-looping container can write tens of gigabytes — this is a top-three cause of “my server’s disk filled up overnight.” Cap it per service or, better, once for the whole host in /etc/docker/daemon.json:
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
Thirty megabytes of retained logs per container is plenty for home debugging, and Dozzle (our logs guide) makes what remains easy to read.
A sane default block
Most home services deserve the same starter stanza: unless-stopped, a memory limit, log caps, and no-new-privileges. Add healthchecks to infrastructure, read-only and cap-drop where the app tolerates them, and you have closed the failures that actually happen at home — runaway memory, silent wedges, full disks, crash loops — without turning Compose files into a second job. The Compose Generator covers the service definitions; this hardening layer is the ten lines you add by hand.
Official documentation and references
- Docker Compose healthchecks — the official how-to
- Docker resource constraints — memory and CPU limit semantics
- Docker logging configuration — the json-file driver and its rotation options
Frequently asked questions
Do resource limits work in plain Docker Compose, or do I need Swarm?
They work in Compose v2 on a single host: the deploy.resources.limits syntax is honored by `docker compose up` for memory and CPU. This was not true of the oldest Compose versions, which is why outdated posts claim otherwise. Verify with `docker stats` after applying — the limit column should show your ceiling instead of the host total.
What happens when a container hits its memory limit?
The kernel’s OOM killer terminates a process inside that container — usually the container itself, which then restarts per its restart policy. That is the intended trade: one service blips instead of the host degrading or killing something unrelated, like your database. If a container hits its limit regularly, the limit is a sizing signal, not a malfunction.
My container has no curl or wget for a healthcheck. What then?
Use what the image does ship: many database images include their own status tools (pg_isready, mariadb-admin ping), some apps expose a CLI health command, and as a fallback a shell TCP check works in images with bash. For images with truly nothing, healthcheck the port from a tiny sidecar or accept Docker-level monitoring only — but give your databases and proxy a real check; they matter most.
Should every container run read-only with all capabilities dropped?
As a direction, yes; as a blanket change, no. Apply per service and test — a minority of apps write to unexpected paths or need a specific capability (VPN containers need NET_ADMIN; some need CHOWN or SETUID for their entrypoints). The settings that are safe almost universally are no-new-privileges, log caps, and restart policy; do those everywhere first.

