Skip to content
DevOps AI ToolKit
Newsletter
All prompts
Docker with AI Difficulty: Advanced ClaudeChatGPTCursor

Container CPU & Memory Limit Right-Sizing Prompt

Right-size Docker CPU and memory limits/reservations from observed usage so containers stop getting OOM-killed or CPU-throttled without wasting capacity.

Target user
DevOps and platform engineers running containers in production
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior container performance engineer who sets CPU and memory limits from measured behavior, not guesswork.

I will provide some or all of:
- `docker stats --no-stream` output for the container(s) over a representative window
- The container's `docker inspect` HostConfig (Memory, MemorySwap, MemoryReservation, NanoCpus/CpuQuota, CpuShares, OomKillDisable)
- `docker events` or `dmesg` lines showing any OOM kills, plus State.OOMKilled from inspect
- The workload profile: language/runtime (JVM, Node, Go, Python), whether it is latency-sensitive or batch, expected concurrency, and any known heap/GC settings
- The host's total CPU and RAM and how many containers share it

Your job:

1. **Characterize the workload** — from the stats, distinguish steady-state usage from peaks; note memory that grows monotonically (possible leak) versus sawtooth GC behavior; identify whether CPU is bursty or sustained.
2. **Diagnose the current limits** — explain what the existing `--memory`, `--memory-reservation`, `--cpus`/`--cpu-quota`, and `--cpu-shares` values actually do, and where they cause OOM kills (exit 137) or CFS throttling.
3. **Recommend hard vs soft limits** — propose a `--memory` hard limit with adequate headroom above observed peak (state the headroom % and why), a `--memory-reservation` soft floor, and whether to disable swap accounting. Warn against `--oom-kill-disable` without a memory limit.
4. **Size CPU correctly** — recommend `--cpus` (NanoCpus) for absolute caps versus `--cpu-shares` for relative weighting, and flag CFS throttling risk for latency-sensitive services under tight `--cpu-quota`.
5. **Align the runtime** — call out when the runtime is unaware of the cgroup limit (e.g. a JVM without container-aware heap settings, or Node's default old-space) and give the specific flag/env to fix it.
6. **Provide the exact config** — output the corrected `docker run` flags AND the equivalent Compose `deploy.resources.limits`/`reservations` block, plus a validation step (what `docker stats` should look like after the change).

Output as: (a) workload characterization, (b) issues with current limits, (c) recommended memory settings with headroom rationale, (d) recommended CPU settings, (e) runtime alignment flags, (f) copy-paste run + Compose config, (g) post-change validation.

If the sample window is too short or lacks a peak, say what additional data to capture and for how long before committing to limits.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Docker with AI prompts & error guides

Browse every Docker with AI prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.