URL: https://forums.docker.com/t/no-space-left-on-device-error/10894/15

UPDATE 2020

As Greg Brown pointed out, the new way is:

docker container prune
docker image prune

Original blog post...


 

If you run out of disk space in your Docker containers on OSX, this is probably the best thing to run:

docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")

The Problem

This isn't the first time it's happened so I'm blogging about it to not forget. My postgres image in my docker-compose.yml didn't start and since it's linked its problem is "hidden". Running it in the foreground instead you can see what the problem is:

▶ docker-compose run db
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
initdb: could not create directory "/var/lib/postgresql/data/pg_xlog": No space left on device
initdb: removing contents of data directory "/var/lib/postgresql/data"

Docker on OSX

I admit that I have so much to learn about Docker and the learning is slow. Docker is amazing but I think I'm slow to learn because I'm just not that interested as long as it works and I can work on my apps.

It seems to me that there's a cap of all storage of all Docker containers in one big file in OSX. It's capped to 64GB:

▶ cd ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/

com.docker.docker/Data/com.docker.driver.amd64-linux
▶ ls -lh Docker.qcow2
-rw-r--r--@ 1 peterbe  staff    63G Oct  3 08:51 Docker.qcow2

If you run the above mentioned commands (docker rm ...) this file does not shrink but space is freed up. Just like how MongoDB (used to) allocates much more disk space than it actually uses.

If you delete that Docker.qcow2 and restart Docker the space problem goes away but then the problem is that you lose all your active containers which is especially annoying if you have useful data in database containers.

Comments

Post your own comment
john

I'm taking a guess, but the space issue is probably related to this:

"This example specifies that the PATH is ., and so all the files in the local directory get tard and sent to the Docker daemon. The PATH specifies where to find the files for the “context” of the build on the Docker daemon. Remember that the daemon could be running on a remote machine and that no parsing of the Dockerfile happens at the client side (where you’re running docker build). That means that all the files at PATH get sent, not just the ones listed to ADD in the Dockerfile." source: https://docs.docker.com/engine/reference/commandline/build/#examples

Anonymous

Thank you for the post. This really solved my issue

Anonymous

Thank you..!!

Anonymous

Thanks for the post!

Anonymous

yep, it works!

Anonymous

Many thanks!

Anonymous

thank you for this post, it really helped

Vincent

I can't ever thought this by myself. Thanks!

Greg Brown

Thanks for this - just wanted to add that in 2019 it's a little easier:

docker container prune
docker image prune

Anonymous

Thanks Greg!!

Rich

This post and its comments bring joy to my world and give me hope.
Thank you, each and every one of you.

Karsten Silz

Thank you for fixing my Docker problem. I referenced your post here: https://github.com/docker-library/postgres/issues/258#issuecomment-559072843

Anonymous

Thanks for post..only this option worked for me perfectly..

Your email will never ever be published.

Related posts

Go to top of the page