max depth exceeded 🐳 Docker

Error response from daemon: max depth exceeded (too many image layers)

The image has more layers than the storage driver allows (127 for overlay2), usually from repeatedly committing containers or very long Dockerfiles.

Seen on: Docker

Meaning

Each RUN/COPY/ADD and each docker commit adds a layer. Images built by committing a container in a loop, or Dockerfiles with hundreds of steps, exceed the limit.

Common causes

  • Image built via repeated docker commit
  • Very many RUN/COPY instructions
  • Base image already close to the limit

⚡ Quick fix

  1. Combine RUN steps with &&
  2. Use multi-stage builds and copy only the result
  3. Flatten: docker export | docker import

Detailed fix by platform

Dockerfile

  1. RUN apt-get update && apt-get install -y a b c && rm -rf /var/lib/apt/lists/*

How to diagnose

  1. Layers — docker history --no-trunc image | wc -l
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.