Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save frutik/7d99e370b6bb7fc0cac1d6126c895d70 to your computer and use it in GitHub Desktop.
Save frutik/7d99e370b6bb7fc0cac1d6126c895d70 to your computer and use it in GitHub Desktop.
How to resize Docker for Mac Disk image and set the default size for new images

Set the default size for new Docker for Mac disk images

If you are getting the error: No space left on device

Configuring the qcow2 size cap is possible in the current versions:

# my disk is currently 64GiB
$ /Applications/Docker.app/Contents/MacOS/qemu-img info ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
image: /Users/djs/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
file format: qcow2
virtual size: 64G (68719476736 bytes)
disk size: 28G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

# I can increase or decrease the default cap by:
$ cd ~/Library/Containers/com.docker.docker/Data/database/
$ git reset --hard
HEAD is now at 8635944 last-start-time changed at 1480009710
# The com.docker.driver.amd64-linux/disk/size file (and the disk dir) may not exist. If they don't exist create them.
$ cat com.docker.driver.amd64-linux/disk/size
65536
$ echo 131072 > com.docker.driver.amd64-linux/disk/size
$ git add com.docker.driver.amd64-linux/disk/size
$ git commit -s -m 'increase size to 128GiB'
[master 60861de] increase size to 128GiB
 1 file changed, 1 insertion(+), 1 deletion(-)

# delete the disk -- this unfortunately deletes all images and containers
$ rm ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2
# now I need to restart the app

For anyone wanting to use an external drive, you can also change the location of the Docker.qcow2 by editing the database key com.docker.driver.amd64-linux/disk/path. There is no UI element for this yet.

Credit for this procedure goes to @djs55 and was taken from docker/for-mac#371 (comment) .

Resize existing Docker for Mac disk image

If you are getting the error: No space left on device

Download gparted from http://gparted.org/download.php.

Close the Docker for Mac Application and wait for it to shutdown completely.

brew update
brew install qemu
cd ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/
qemu-img info Docker.qcow2   # shows you current disk size
qemu-img resize Docker.qcow2 +100G  # make it 100GB larger
qemu-img info Docker.qcow2    # check the new size
qemu-system-x86_64 -drive file=Docker.qcow2  -m 512 -cdrom ~/Downloads/gparted-live-0.27.0-1-i686.iso -boot d -device usb-mouse -usb

Wait for the VM to boot (can take a long time). For any questions asked (boot option, keyboard layout, language) the default is ok. Double click the gparted Icon. You should see swap space, the main partition and 100GB of free space. Select the main partition. Click Resize in the toolbar and drag the partition limit to fill the whole space. Click Apply. Wait for it to finish resizing and then quit the app and shutdown the gparted machine. Now start Docker for Mac again.

Run the following command to check the available diskspace inside the docker vm:

docker run --rm --privileged debian:jessie df -h

Make sure you shut down the gparted vm cleanly and don't access Docker.qcow2 while the procedure is running. Otherwise the disk image might get corrupted.

Credit for this procedure goes to the conversation in https://forums.docker.com/t/consistently-out-of-disk-space-in-docker-beta/9438/6. Especially to jgielstra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment