Docker Cleaning
How I clean out old Docker data.
Cleaning up Docker
I’ve been recreating Docker images a lot for work. This seems to slowly balloon the Docker disk image, so I’ve had to work out how to clean everything out.
… since I obviously don’t deploy on my workstation there’s nothing that needs to be kept …
This might not work with Hyper-V Docker on Windows; I don’t have access to Hyper-V flavour.
- stop/remove all docker containers
docker stop $(docker ps -aq)
docker rm -f $(docker ps -aq)
- if you don’t have “bash stuff” you can run
docker ps -aq
and then copy/paste the ids for docker stop / docker rm -f - … i don’t have bash stuff …
- run the prune thing
docker system prune -a --volumes
- defragment the virtual disk (this is probably the important part)
- open power shell as admin
wsl --shutdown
- docker dekstop will pop up an error message (ignore it until you’re done)
- open diskpart with the
diskpart
command - run the following steps
- … adjust the file command to match where youh
.vhdx
is - it should be big select vdisk file="C:\Users\peter\AppData\Local\Docker\wsl\disk\docker_data.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
- … adjust the file command to match where youh
- if there’s still a shortage of disk space … idk …
- Diskitude (or whatever) visualises disk usage https://madebyevan.com/diskitude/
- … so i’ve been using that to locate large things i don’t need
- when done, restarting Docker Desktop (or clicking the “Restart” button on that error message) gets everything rolling again