DEV Community

Cover image for 10 Docker Disk Habits That Stop Your Image Builds From Failing
flisk
flisk

Posted on Edited on

10 Docker Disk Habits That Stop Your Image Builds From Failing

Image builds fail in ways that do not mention disk. The fix is usually a cleanup. These ten habits keep a laptop out of that corner.

Flow from flisk doctor's free-space check through docker system df and builder prune to system prune as the last resort.

  1. Check free space before a big build. flisk doctor reports it. One run on a laptop said "4.8 GiB free on this machine: building images needs at least 5 GiB".
  2. Prune the build cache first. docker builder prune -f is the gentle option.
  3. Use docker system prune -af last. It removes unused images, containers and networks. Know what you will lose.
  4. Look before you prune. docker system df shows where the space went.
  5. Keep images small. Smaller base images, fewer layers, multi-stage builds.
  6. Use a .dockerignore. Do not copy node_modules, target or .git into the build context.
  7. Order Dockerfile layers by change. Dependencies first, source last, so the cache survives.
  8. Remove stopped stacks. flisk down removes the containers it started.
  9. Watch Rust and Node builds. They produce large intermediate output.
  10. Set a reminder. A monthly prune is cheaper than a failed build at a bad moment.

The rule

Disk is a resource like memory. Check it first, and the strange failures go away.

Top comments (0)