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")
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"
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.