'Docker for Windows cleanup
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
Solution 1:[1]
Since Docker 1.13 (January 2017), Docker has some new canonical pruning subcommands (use with care):
-
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
However, Docker Desktop has had some sketchy upgrades that left things behind, which required manual file removal or "factory resets" for some folks.
- Manual Deletion
- Mac - https://github.com/docker/for-mac/issues/371 (This one got me a week or so ago. I resorted to pruning and deleting data with
rm -rf ~/Library/Containers/com.docker.docker/Data/*
) - Win - https://github.com/docker/for-win/issues/745#issuecomment-319930974
- Mac - https://github.com/docker/for-mac/issues/371 (This one got me a week or so ago. I resorted to pruning and deleting data with
- Factory Reset In the Docker Preferences GUI, there is a "reset to factory defaults" option. (In Docker Desktop for Mac v3.3, the option is in the "troubleshoot" tab, the icon for which looks like a bug. )
Solution 2:[2]
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
Solution 3:[3]
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
Solution 4:[4]
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
Solution 5:[5]
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.
Solution 6:[6]
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
Solution 7:[7]
Try
icacls "C:\ProgramData\Docker" /T /C /grant Administrators:F
as administrator
Solution 8:[8]
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}
Solution 9:[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
Works fine for me.
Solution 10:[10]
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
- Rename docker folder inside c:\ProgramData\Docker\ to something like c:\ProgramData\Docker.old\
- Run git bash inside c:\ProgramData\
- rm -rf Docker.old\
I think the above workaround will also work with WSL terminal, but haven't tested myself
Solution 11:[11]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow