Reduce Docker qcow2 size on Mac OS X

If you have Docker on Mac, you'll eventually notice that Docker is taking way too much space, go ahead, check how much it's using now:

du -hs ~/Library/Containers/com.docker.docker

Apparently I'm not the only one out there that have this issue, see this for proof. The issue is actually caused by Docker's "qcow2" disk just keep growing. Docker apparently have no reliable way to run TRIM on the disk.

Fortunately the Internet has come to rescue, you can run the TRIM command from a debian docker image, here one command that created by one of the commenter.

Just run this command to reduce the size:


docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n fstrim /var


It's going to take a while if your qcow2 is huge.

Once it finishes, verify the size again with

du -hs ~/Library/Containers/com.docker.docker


There's also a built-in docker commands that removes dangling images - which could reclaim some disk space.

docker image prune


Update Jul 14, 2017 - Switch to "walkerlee/nsenter" nsenter image, because it's less than 600Kb.

Comments

  1. Hi there getting the belwo error when I try and run the fstrim comman. Any thoughts?

    fstrim: /var: the discard operation is not supported

    ReplyDelete

Post a Comment