How to shrink Docker disk image, but keep volumes in Docker for Mac?

Viewed 731

When decreasing the size of the Docker disk image, Docker for Mac gives a warning, that it will delete all images, containers and volumes. enter image description here

I don't mind losing the images and containers, but is there a way to preserve the volumes? Is there a way to temporarily "copy" the volumes from the Docker disk image to another part of the host file system, shrink the disk image, than copy the volumes back to it?

1 Answers

The volumes are at /mnt/sda1/var/lib/docker and /var/lib/docker/volumes; you could try ssh'ing into the VM and copying them back and forth. I've never tried it myself though.

Also, I'm not sure about how a mac deals with the docker VM, but on Windows we can manipulate the size of the VM file itself by using the Wizard in the Hyper-V manager. Maybe there's something similar in a Mac? Then you'd be bypassing the Docker UI's way of adjusting the VM size.

Related