Useful or not, from you.
for-win Windows 10: Docker does not release disk space after deleting all images and containers

<!-- If you are reporting a new issue, make sure that we do not have any duplicates already open. You can ensure this by searching the issue list for this repository. If there is a duplicate, please close your issue and add a comment to the existing issue instead.

If you suspect your issue is a bug, please edit your issue description to include the BUG REPORT INFORMATION shown below. If you fail to provide this information within 7 days, we cannot debug your issue and will close it. We will, however, reopen it if you later provide the information.

For more information about reporting issues, see https://github.com/docker/docker/blob/master/CONTRIBUTING.md#reporting-other-issues


GENERAL SUPPORT INFORMATION

The GitHub issue tracker is for bug reports and feature requests. General support can be found at the following locations:

  • Docker Support Forums - https://forums.docker.com
  • IRC - irc.freenode.net #docker channel
  • Post a question on StackOverflow, using the Docker tag

BUG REPORT INFORMATION

Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST -->

Description When running docker images using Windows 10 professional, the docker virtual disk MobiLinuxVM.vhdx keeps on growing. After having finished with the images/container, and deleting them all, the virtual disk does not shrink in size. Expected behavior: MobiLinuxVM.vhdx should shrink and release the unused space.

Steps to reproduce the issue:

  1. Run various containers and observe that MobiLinux grows (once a container was running, I added my own software, which amounted to about 20GB).
  2. Deleted all containers & images using: docker rm $(docker ps -a -q) and docker rmi $(docker images -q).

Describe the results you received: MobiLinuxVM.vhdx still 40+GB in size

Describe the results you expected: MobiLinuxVM.vhdx should have "shrunk" to its original size when initially installing Docker on my Windows 10 box.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 23:26:11 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 23:26:11 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 0
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: null host bridge overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.4.27-moby
Operating System: Alpine Linux v3.4
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.919 GiB
Name: moby
ID: IWNC:POO5:TSO4:GIAK:MLHK:C46G:DRJF:IWBM:YSRO:COUL:6TKR:M2ZC
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 12
 Goroutines: 22
 System Time: 2016-11-20T17:06:20.2301916Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
WARNING: No kernel memory limit support
Insecure Registries:
 127.0.0.0/8

Additional environment details (AWS, VirtualBox, physical, etc.): Windows 10 professional. Docker latest install using Hyper-V.

That's a useful answer
Without any help

This works for me to get it to compact. I use zerofree to zero out the unused blocks, which then allows Optimize-VHD to reduce the size of the file. However, the filesystem has to be unmounted for zerofree to work, so I attach the disk to a different VM:

  1. Open Hyper-V Manager. You should see DockerDesktopVM or MobyLinuxVM, which is the VM whose disk has the docker data. Create another VM running Ubuntu using the Quick Create menu.
  2. In the settings for the Ubuntu VM, under SCSI Controller, add a second hard drive. Select the DockerDesktop.vhdx file.
  3. Start the Ubuntu VM (if it's the first start you'll have to do some initial setup). Use a tool such as gparted (sudo apt install gparted) to shrink the partition containing the Docker data (the partition is likely /dev/sdb1 if you have mounted the disk as described above). Shrink it to a size slightly larger than the amount of data present. Then resize it again to the maximum size available on the virtual disk. This seems to have the effect of moving all the data to the beginning of the partition.
  4. Run zerofree on the partition: sudo apt install zerofree and sudo zerofree /dev/sdb1. This ensures that the empty part of the disk is all zeros.
  5. When zerofree is done, shut down the Ubuntu VM. Then use the Edit Disk wizard in Hyper-V Manager to compact the DockerDesktop.vhdx, or run Optimize-VHD 'C:\Users\Public\Documents\Hyper-V\Virtual hard disks\DockerDesktop.vhdx' -Mode Full in PowerShell.
  6. You can keep the Ubuntu VM around for next time, or delete it and delete the Ubuntu disk image in C:\Users\Public\Documents\Hyper-V\Virtual hard disks\.