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
  • if there’s still a shortage of disk space … idk …
  • when done, restarting Docker Desktop (or clicking the “Restart” button on that error message) gets everything rolling again
comments powered by Disqus
Peter LaValle avatar
Peter LaValle
Any links probably include affiliate ids for that sweet sweet kickback - and some programs require that I tell you. The contents of this blog are likely unrelated - as they include games, paints, and build tools.