Reclaiming disk space without messing up my dev environments

Setup
Mac, docker desktop, 14 containers

Context
Drupal, wordpress, api, solr, react, etc development
Using docker compose and ddev
Using docker handson (so not really interested in how it works, but happy to work with it)

Problem
Running out of diskspace
Last time i reclaimed diskspace I lost all my local environments, had to rebuild all my containers from git and the production databases, so I really did something stupid. and cost me a lot of time.

I found some answers to the following (hopefully not too stupid) questions but but as I am pressed for time and deadlines am afraid to implement them.

f.i.
docker volume prune
docker rmi $(docker images -a)

Question 1
What is a save way to reclaim disk space?

Question 2
How can I backup an whole setup (so for a project all containers, images, volumes) so that when I destroy them I could easily restore them from my backup?

Hi.

I think the following command would be good for managing the image.

Compression (The file size decreases as it goes down)

docker image save [docker image name] > [save image name].tar

docker image save [docker image name] | gzip > [save image name].tar.gz

docker image save [docker image name] | bzip2 > [save image name].tar.bz2

Extract
docker image load < [docker image name].tar

I’m curious about other opinions than mine.
and other volume, log, network, etc

Have you read the Docker Desktop for Mac FAQ?

2 Likes

Hi, I ran this command right now on Mac, however

data % ls -klsh Docker.raw 
92956020 -rw-r--r--@ 1 ...  staff   104G 19 Mai 08:00 Docker.raw
(base) ...@Mac data % docker run --privileged --pid=host docker/desktop-reclaim-space
Unable to find image 'docker/desktop-reclaim-space:latest' locally
latest: Pulling from docker/desktop-reclaim-space
5bc638ae6f98: Pull complete 
Digest: sha256:8b26e45c51632fd78131f3bddca76122bebc1dd8376f16dd26f769c7f33121fd
Status: Downloaded newer image for docker/desktop-reclaim-space:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
(base) ...@Mac data % ls -klsh Docker.raw                                            
92956132 -rw-r--r--@ 1 ...  staff   104G 19 Mai 08:03 Docker.raw

It didn’t do a thing. The required space should be < 30GB.

I tried the mentioned command on my Mac and it still shows the maximum size, not the actual size. Try “du” which shows “disk usage”:

du -sh Docker.raw

This is the difference on my Machine after increased the size to 104GB just to see if increasing it will make a difference before I realized the size was the maximum size:

 ta@ta-mb-2  ~/Library/Containers/com.docker.docker/Data/vms/0/data 
 »  ls -klsh Docker.raw
3051184 -rw-r--r--@ 1 ta  staff   104G Máj 19 22:43 Docker.raw
 ta@ta-mb-2  ~/Library/Containers/com.docker.docker/Data/vms/0/data 
 »  du -sh Docker.raw
2,9G	Docker.raw