38

I'm using docker for Windows to launch a MSSQL server. Everything is working fine except for the fact that my harddrive is now full. I've used all the cleanup commands that docker has, removing all images and containers:

docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q -f dangling=true)
docker rmi $(docker images -q)

This will not remove any contents in the c:\ProgramData\Docker\windowsfilter folder, where there are still a lot of file. Roughly 130gb worth's of storage, without any running containers or stored images.

Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.24)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      windows/amd64
 Experimental: true

I tried to use the docker-ci-zap (https://github.com/jhowardmsft/docker-ci-zap) , but running that tool is not recommended so I would rather use an alternative solution

imacbest
  • 873
  • 1
  • 7
  • 16
  • Have you tried using the -f flag (forced) and also removing the volumes with `docker volume rm [OPTIONS] VOLUME [VOLUME...]` – dsax7 Apr 24 '17 at 13:09
  • Jup also tried that, it keeps the windowsfilter folder, which seems to be the biggest. – imacbest Apr 24 '17 at 13:16
  • Can you please try `docker system prune` and tell us? See: [http://stackoverflow.com/a/43068138/1561148](http://stackoverflow.com/a/43068138/1561148) – tgogos Apr 24 '17 at 15:17
  • I tried that as well, it didnt work. I can remove the whole C:\programdata\docker folder with that docker-ci-zap tool, but it doesnt seem to be the right answere, since the creators dont recommend it(?). – imacbest Apr 24 '17 at 20:38
  • hey @imacbest have you found a solution for that? – felixsigl Jul 19 '17 at 13:36
  • @felixsigl Nope haven't found a solution, for know I just use the docker-ci-zap whenever I run out of diskspace. This setup is not ideal since I need to remove everything and sometimes the setup breaks. I hope the windows docker team will add a good cleanup feature in the future... – imacbest Jul 20 '17 at 13:58

11 Answers11

33

Since Docker 1.13 (January 2017), Docker has some new canonical pruning subcommands (use with care):

However, Docker Desktop has had some sketchy upgrades that left things behind, which required manual file removal or "factory resets" for some folks.

Jamie Jackson
  • 1,158
  • 3
  • 19
  • 34
  • make sure RESTART the docker for windows, after running these prune commands or you won't see any significant change in MobyLinuxVM size – Arash Dec 21 '18 at 18:33
  • On Windows, the following script helps determine which `windowsfilter` subfolders are unused and can be deleted: https://gist.github.com/olljanat/340b4033eb24d8d33ec75f2c3c3b6b3d – sparrowt Jan 30 '19 at 09:32
  • 6
    **Note** make sure you try in _Windows containers_ mode as well as _Linux containers_ mode (right-click on Docker tray icon > _'Switch to Windows containers...'_), otherwise `docker system prune` and friends will not be able to clean up files related to Windows containers (`ProgramData\Docker\windowsfilter`) – sparrowt Jan 30 '19 at 12:13
  • @sparrowt thanks, this is the solution I was looking for. – pascalre Sep 22 '21 at 14:40
10

From a powershell window:

docker system prune -a -f
net stop com.docker.service
taskkill /F /IM "Docker Desktop.exe"
stop-vm DockerDesktopVM
Optimize-VHD -Path "C:\ProgramData\DockerDesktop\vm-data\DockerDesktop.vhdx" -Mode Full
start-vm DockerDesktopVM
start "C:\Program Files\Docker\Docker\Docker Desktop.exe"
net start com.docker.service
Delirante
  • 809
  • 8
  • 12
  • I ran out of space while importing images, and `docker system prune -a -f` was the only one that cleared the `windowsfilter` folder for me. – Cpt.Whale Apr 28 '21 at 18:29
  • 1
    As commented above by sparrowt: Note make sure you try in Windows containers mode as well as Linux containers mode (right-click on Docker tray icon > 'Switch to Windows containers...'), otherwise docker system prune and friends will not be able to clean up files related to Windows containers (ProgramData\Docker\windowsfilter) – victorm1710 Oct 21 '21 at 11:10
9

Had about ~40GB for ext4.vhdx file and ~17gb for ProgramData/Docker Desktop. If you are using Docker Desktop it easy to clean it :

Just open it, click Troubleshoot and then Clean/Purge data

enter image description here

Works fine for me.

Nigrimmist
  • 10,289
  • 4
  • 52
  • 53
  • +1: this actually works! Unlike `docker sytem prune`, which did nothing to the Windows container data piled up in `C:/ProgramData/Docker/windowsfilter` (and, yes, "Switch to Windows Containers" was already applied anyway). Horrible form for `docker system prune` just fail silently like that... – Will Dec 05 '22 at 23:39
7

Just use prune command for docker system and it will clean up every thing just like this

$ docker system prune

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache Are you sure you want to continue? [y/N] y

In Docker 17.06.1 and higher, you can add the --volumes flag for docker system prune to prune volumes not used by at least one container.

For more details https://docs.docker.com/config/pruning/#prune-everything

Schnouki
  • 7,527
  • 3
  • 33
  • 38
Keyur Lakhani
  • 4,321
  • 1
  • 24
  • 35
5

Download docker-ci-zap.exe from https://github.com/jhowardmsft/docker-ci-zap and then run it in powershell with admin priviledge:

.\docker-ci-zap.exe -folder "C:\ProgramData\docker"

Reference: https://github.com/moby/moby/issues/26873

TridenT
  • 4,879
  • 1
  • 32
  • 56
  • I used that tool, but in that same issue there is a warning that the tool might be dangerous, so i was hoping there might be another solution. https://github.com/moby/moby/issues/26873#issuecomment-249338936 – imacbest Apr 16 '18 at 09:16
4

I use WSL 2 and this helped me: Open your PowerShell and enter the following

PS C:\tmp> diskpart

Microsoft DiskPart version 10.0.19041.1

Copyright (C) Microsoft Corporation.
On computer: *****

DISKPART> select vdisk file="C:\Users\<UID>\AppData\Local\Docker\wsl\data\ext4.vhdx"

DiskPart successfully selected the virtual disk file.

DISKPART> compact vdisk

  100 percent completed

DiskPart successfully compacted the virtual disk file.

Try wsl --shutdown in PowerShell if it claims another process uses this disk

Source

Paul
  • 571
  • 3
  • 17
3

I had a similar issue after running windows containers. My windowsfilter folder size increased to ~80GB and I couldn't delete those files manually or with docker system prune --valume. After googling so many hours, I always ended with the docker-ci-zap.exe solution which is not recomended. Then I figured out a easy workaround by reading https://github.com/docker/for-win/issues/745#issuecomment-444461889.

The workaround is adding -removing suffix to the folders you wish to delete within windowsfilter directory and restart the docker. This will trigger docker to cleanup the folders properly at startup. I have experienced docker will clean at most 10 folder in every startup. If you have more then 10 folders, then you might restart several time to remove all of them.

You can use the following command if you want to get ride of all the files.

Get-ChildItem -Path D:\docker\data\windowsfilter -Directory | % {Rename-Item $_.FullName "$($_.FullName)-removing" -ErrorAction:SilentlyContinue}

Jeba Ranganathan
  • 532
  • 1
  • 8
  • 5
  • I really wished this worked but on Docker Community Edition V18.03.0-ce-win59 (16752) this is not removing any folders. – Daniel Apr 22 '21 at 06:07
  • Worked on docker for windows 4.6.0. – Kamil C Apr 23 '22 at 09:50
  • For me docker was deleting more than 10 files everytime I stopped the service, after a couple of restarts all files where deleted – enwi May 24 '23 at 05:50
2

If still relevant. I ran into the same thing.

Try the command

docker rmi

In my case problem was in that I tried execute it in linux containers mode.

When I switched into windows containers this command executing removed all content of this folder.

afkelarion
  • 59
  • 4
  • 1
    This solved my problem, thank you. I switched to Windows Containers mode and ran: `docker system prune` – demius May 02 '19 at 05:53
1

Try

icacls "C:\ProgramData\Docker" /T /C /grant Administrators:F 

as administrator

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
1

Solution update for 2021

NOTE:
All command executed in ADMIN powershell

First step: Clean all the images and the volumes.

docker image ls # These images will be all deleted
docker image prune -a -f

docker volume ls # These volumes will be all deleted
docker volume prune -a -f

docker system prune -a -f

Second step: Stop docker service

Right click on the docker icon or taskkill /F /IM "Docker Desktop.exe". Then: net stop com.docker.service

Third step: Reduce the .vhdx file size

Optimize-VHD -Path "C:\Users\alessiosavi\AppData\Local\Docker\wsl\data\ext4.vhdx" -Mode Full

Now you can restart the docker service: net start com.docker.service

alessiosavi
  • 2,753
  • 2
  • 19
  • 38
0

I faced similar issue trying to delete docker folder for cleanup, the below simple trick worked for me

Pre-requisite : Needs git bash to be installed

  1. Rename docker folder inside c:\ProgramData\Docker\ to something like c:\ProgramData\Docker.old\
  2. Run git bash inside c:\ProgramData\
  3. rm -rf Docker.old\

I think the above workaround will also work with WSL terminal, but haven't tested myself