How to Fix no space left on device (Docker) (Docker)
Quick Answer: The 'no space left on device' error in Docker typically means your disk is full, preventing Docker from writing new data. The fastest fix is to clean up unused Docker objects using `docker system prune -a` to free up significant space.
What Causes This Error
- Accumulation of unused Docker images
- Accumulation of stopped containers
- Accumulation of unused Docker volumes
- Accumulation of build cache from multi-stage builds
- Host machine's disk is genuinely full, unrelated to Docker's internal usage
Step-by-Step Fixes
Fix 1: Prune all unused Docker objects
Run `docker system prune -a` in your terminal. This command removes all stopped containers, all dangling images, and all unused networks and build cache. Confirm with 'y' when prompted.,Verify disk space with `df -h` to see if sufficient space has been freed.
Fix 2: Remove specific unused images
List all images: `docker images -a`,Identify large or unused images by reviewing the 'SIZE' and 'CREATED' columns.,Remove specific images by ID or name: `docker rmi <image_id_or_name>`.
Fix 3: Remove specific unused containers
List all containers (including stopped ones): `docker ps -a`,Identify stopped containers that are no longer needed.,Remove specific containers by ID or name: `docker rm <container_id_or_name>`.
Fix 4: Remove unused volumes
List all volumes: `docker volume ls`,Identify volumes not associated with any running containers. These are often created by accident or left over from deleted containers.,Remove specific volumes: `docker volume rm <volume_name>`.
Fix 5: Inspect Docker disk usage
Run `docker system df` to get a detailed breakdown of Docker's disk usage, including images, containers, and volumes. This helps pinpoint where space is being consumed.
Fix 6: Increase host machine disk space
If Docker objects have been pruned and the issue persists, the host machine's disk may be genuinely full. Use `df -h` to check overall disk usage.,Delete non-Docker files, expand the virtual disk (if on a VM), or add more physical storage.
Advanced Fixes
Advanced Fix 1: Advanced Fix: Identify and clean up large image layers
Identify large images: `docker images --format '{{.Size}} {{.ID}} {{.Repository}}:{{.Tag}}' | sort -rh`,Inspect specific image layers to find large files: `docker history --no-trunc <IMAGE_ID>` (Look for layers with large sizes).,If an image is no longer needed and not used by any running containers, remove it: `docker rmi <IMAGE_ID>`
Advanced Fix 2: Advanced Fix: Analyze and clear large container logs
List container log file sizes: `sudo du -sh /var/lib/docker/containers/*/ *-json.log` (adjust path for your OS).,Identify the container ID associated with large logs.,Clear logs for a specific container (requires Docker daemon restart or log rotation configuration): `sudo truncate -s 0 /var/lib/docker/containers/<CONTAINER_ID>/<CONTAINER_ID>-json.log`,Alternatively, configure log rotation for all containers in `/etc/docker/daemon.json` (e.g., `{"log-opts": {"max-size": "10m", "max-file": "3"}}`) and restart Docker: `sudo systemctl restart docker`
Advanced Fix 3: Advanced Fix: Move Docker data directory to a larger disk
Stop Docker daemon: `sudo systemctl stop docker` (or equivalent for your OS).,Create a new Docker data directory on the larger disk: `sudo mkdir -p /mnt/new_disk/docker-data`,Copy existing Docker data: `sudo rsync -aqxP /var/lib/docker/ /mnt/new_disk/docker-data`,Configure Docker to use the new directory by editing `/etc/docker/daemon.json`: `{"data-root": "/mnt/new_disk/docker-data"}`,Start Docker daemon: `sudo systemctl start docker`,Verify Docker is using the new path: `docker info | grep 'Docker Root Dir'`
Advanced Fix 4: Advanced Fix: Clean up dangling build cache
List build cache entries: `docker builder prune --dry-run`,Remove dangling build cache: `docker builder prune -f`
FAQs
Q:
A:
Q:
A:
Q:
A:
Q:
A:
Q:
A: