![](/uploads/1/2/6/6/126671016/878513858.jpg)
10 Ways To Free Up Disk Space on Your Mac Hard Drive. Lowell Heddings @lowellheddings June 19, 2018, 4:04am EDT. Even in 2018, MacBooks still have tiny hard drives that fill up quickly. Luckily there are quick and easy ways to free up space on your hard drive. Here’s how to clean up your Mac and reclaim some drive space.
Under the hood, Docker for Mac is runningan Alpine Linux virtual machine. This guidehelps with issues related to communication between OS X/macOS and this VM, andrunning up against limits on the size of the disk allocated to the VM.
- Speeding things up
- Freeing disk space
- Getting a shell in the VM
Speeding things up
Disable sync on flush
This speeds up write operations involving containers. The tradeoff is increasedrisk of data loss: pending writes will be lost if your computer, Docker, or acontainer crashes. Since Docker for Mac is used for development, not production,this may be a good tradeoff to make. Here's how:
References:
overlay2 storage engine
If you installed Docker for Mac a while ago, it's probably using the aufsstorage engine. overlay2 is a newer, more performant storage engine. Fromhttps://docs.docker.com/engine/userguide/storagedriver/selectadriver/#docker-ce:
When possible, overlay2 is the recommended storage driver. When installingDocker for the first time, overlay2 is used by default. Previously, aufs wasused by default when available, but this is no longer the case.
On existing installations using aufs, it will continue to be used.
Elsewhere, this page says:
Docker for Mac and Docker for Windows are intended for development, ratherthan production. Modifying the storage driver on these platforms is notpossible.
But this is not true: you can use overlay2 with Docker for Mac.
Switching storage engines changes where Docker looks for containers and images,so none of the ones you had with the old storage engine will be found. When youbuild images, Docker will download new ones to be stored using the new storageengine. Once you're happy with the new storage engine, you can temporarilyswitch back, delete all the images and containers associated with the old one,and then return to the new storage engine.
Not sure if you need to switch? Check first:
To switch, go to Docker, Preferences, Daemon, Advanced, and add the followingkey/value pair to the json in the box:
Click Apply & Restart.
References:
Docker-sync
Some people use Docker-sync for better performance, especially when using PHPprojects like Symfony or Drupal. I haven't used it myself, so here's where tolearn more:
Freeing disk space
The VM disk has a limit on how big it can grow, so it can run out of space,resulting in errors when trying to build images.
Additionally, you may want to reclaim space from the VM disk image for your ownuse, particularly if you know that you are storing images and containers thatyou no longer need.
Diagnosis
What size is your VM's disk?
64G for the VM. How much space is left on it?
Only 5.2G left on
/
! Pull a few more big images, or build a large projectinside a container, and this VM could run out of space.Subproblem 1: removing unneeded images and containers
- Start containers that you know you want to keep.
- Using Spotify's docker-gc, do a dryrun to see what would be deleted:$ docker run --rm -e DRY_RUN=1 -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc:ro spotify/docker-gc
- If that looks good, do the real thing:$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc:ro spotify/docker-gc
References:
Pruning volumes
More about this to come.
Alternative
docker-clean provides a nicewrapper around the actual docker commands.
Subproblem 2: reclaiming space for VM and host
Now that unneeded images and containers are gone, we want to reclaim the diskspace they occupied for use by the host and/or the VM.
Docker for Mac (after version 1.12) is supposed to run TRIM every 15 minutesusing a cron job. If you want to manually trigger a TRIM:
The first time I tried this, nothing happened until I restarted Docker. Afterrestarting, hyperkit went to max cpu for hours. While it was running, dockercommands hung. Once it finished, I had to restart Docker again. It had freed up30 GB!
Since then, it has worked (freeing space on the VM and on the host) without arestart.
References:
- How to resize qcow image: https://gist.github.com/stefanfoulis/5bd226b25fa0d4baedc4803fc002829e
Getting a shell in the VM
References:
- http://blog.kontena.io/docker-for-mac-glibc-issues/ (provides full explanationof all the flags)
Alternative: attach to tty
This isn't really getting a shell, but rather using GNU screen to connect to atty device. Don't exit the shell; instead, tell screen to detach by typing
Control-a d
. To re-attach:If you simply attach screen again, the terminal text will be garbled.
References:
Problems with tar
macOS uses GNU tar. Inside a Linux-based image, the tar that's available islikely GNU tar. If you encounter errors like 'Directory renamed before itsstatus could be extracted', they might stem from running GNU tar inside an imageon a tarball created by BSD tar (outside of the image).
![Docker For Mac Increase Disk Space Docker For Mac Increase Disk Space](/uploads/1/2/6/6/126671016/534041094.png)
Try either:
- Install GNU on your host and use it:
- Or use BSD tar inside the image by installing it in your Dockerfile:
More!
Got more tips? This is a living document. Please leave a comment below.
![](/uploads/1/2/6/6/126671016/878513858.jpg)