Docker error : no space left on device – How to solve it?

In this article I am going to show you different ways of solving the Docker error : no space left on device, a common issue found by many Docker users.

Experiencing a “no space left on device” error in Docker can be a hassle, especially when you’re trying to pull a new image like Elasticsearch. This tutorial, inspired by community insights, will guide you through several steps to troubleshoot and solve this issue.

Understanding the Issue

Docker utilizes /var/lib/docker for storing its images and container runtime environment. When this directory fills up, you’re likely to encounter the “no space left on device” error.

Step-by-Step Solutions

Step 1: Check Disk Usage

First, assess how much space /var/lib/docker is using:

du -sh /var/lib/docker

This command will give you an idea of the space occupied by Docker.

Step 2: Manage Disk Space

If your disk is full, you have two main options:

  1. Mount a Larger Disk: If you consistently run many images and applications, consider mounting a disk with more space.
  2. Cleanup Unused Images and Containers:
    • Remove unused Docker images:
      docker image rm <image-name/image-id>
    • Remove stopped Docker containers:
      docker container rm <container-name/container-id>

Step 3: Utilize Docker System Prune

For a broader cleanup, use the Docker system prune command:

docker system prune --all --force

This command removes:

  • All stopped containers
  • All unused networks
  • All dangling images
  • All build caches

To also remove unused volumes, add the --volumes flag:

bashCopy code

docker system prune --all --force --volumes

Step 4: Inspect Docker Volumes

Volumes can also occupy significant space. List all volumes with:

docker volume ls

Review and remove any volumes not in use.

Step 5: Check Filesystem Type

If you’re still encountering issues, check your filesystem:

docker info | grep Filesystem

  • For ext4 Filesystem: Be aware of inode exhaustion, which can cause a ‘no space left’ error.
  • For xfs Filesystem: This is often more compatible with Docker, especially when formatted with specific flags for overlay2 as the storage driver.

Community Confirmation

Many users have found that executing docker system prune --all --force --volumes successfully freed up a considerable amount of space.

Conclusion

Following these steps should help resolve the “no space left on device” error in Docker. Regular maintenance, such as removing unused images and containers, along with understanding your filesystem’s nuances, can prevent this issue from recurring.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top