Freeing up space used by docker containers.

When building or working with docker containers, you may get error messages like the one below relating to a lack of space:

failed to copy files: failed to copy directory: Error processing tar file(exit status 1): write /<directory>: no space left on device

The error occurs because Docker objects accumulate over time and can eventually exhaust available storage. To resolve do the following:

docker system df

This will tell you how much space Docker objects are taking up in your machine. Docker includes a prune command that allows you to reclaim space. You can use prune to delete all objects or some images. You can read more about it in the docs.

# Prune everything
docker system prune

# Only prune images
docker image prune

This will hopefully clear up space. If this doesn’t work, you may need to allocate more disk space to docker.