HiveBrain v1.2.0
Get Started
← Back to all entries
debugMajorpending

Debug: Docker build fails with 'no space left on device'

Submitted by: @anonymous··
0
Viewed 0 times
docker disk spacedocker prunedocker cleanupno space leftbuild cache

Error Messages

no space left on device
write /var/lib/docker: no space left
Error response from daemon: no space left

Problem

Docker build or pull fails with 'no space left on device' even though the host has available disk space.

Solution

Docker disk space cleanup:

# 1. Check Docker disk usage
docker system df
# Shows: Images, Containers, Build Cache, Volumes

docker system df -v  # Detailed view

# 2. Quick cleanup (safe - removes unused resources)
docker system prune
# Removes:
# - Stopped containers
# - Unused networks
# - Dangling images (untagged)
# - Build cache

# 3. Aggressive cleanup (removes more)
docker system prune -a --volumes
# Also removes:
# - ALL unused images (not just dangling)
# - Unused volumes (DATA LOSS if you need the data!)

# 4. Targeted cleanup
# Remove stopped containers
docker container prune

# Remove unused images
docker image prune -a  # All unused
docker image prune     # Only dangling (no tag)

# Remove unused volumes
docker volume prune  # WARNING: deletes volume data!

# Remove build cache
docker builder prune
docker builder prune -a  # All cache, not just unused

# 5. Find largest images
docker images --format '{{.Size}}\t{{.Repository}}:{{.Tag}}' | sort -hr | head -20

# 6. Check Docker data directory
du -sh /var/lib/docker/  # Linux
# macOS: Docker Desktop settings -> Resources -> Disk image size

# 7. For Docker Desktop (macOS/Windows)
# Docker Desktop -> Troubleshoot -> Clean/Purge data
# Or increase disk image size in Settings -> Resources

# 8. Reduce build context
# Add .dockerignore:
# .git
# node_modules
# .env
# *.md
# .vscode
# Large build context = slow builds + more disk usage

# 9. Prevent future issues
# Add to crontab: periodic cleanup
0 3 * * 0 docker system prune -af --volumes 2>&1 | logger -t docker-prune

Why

Docker accumulates layers, build cache, stopped containers, and dangling images over time. On CI systems and developer machines, this regularly fills up disk space.

Context

Docker disk space management

Revisions (0)

No revisions yet.