Skip to content

Instantly share code, notes, and snippets.

@dcormier
Last active November 5, 2021 19:21
Show Gist options
  • Save dcormier/8b27e61bead4d7293640ad2697647a3f to your computer and use it in GitHub Desktop.
Save dcormier/8b27e61bead4d7293640ad2697647a3f to your computer and use it in GitHub Desktop.
docker cleanup guide (for PowerShell on Windows): containers, images, volumes, networks

Docker - How to cleanup (unused) resources in PowerShell on Windows

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

Based on this gist.

delete volumes

TODO

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm

delete networks

TODO

$ docker network ls  
$ docker network ls | grep "bridge"   
$ docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')

remove docker images

// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images

> docker images
> docker images --filter "dangling=true" -q --no-trunc | ForEach-Object -process {docker rmi $_}

> docker images | % { $_ -replace " +", "," } | convertfrom-csv | Where-Object { ($_.Repository -match "none") -or ($_.Tag -match "none") }
> docker images | % { $_ -replace " +", "," } | convertfrom-csv | Where-Object { ($_.Repository -match "none") -or ($_.Tag -match "none") } | % { docker rmi $_.IMAGE }

remove docker containers

// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images

> docker ps
> docker ps -a
> docker ps -qa --no-trunc --filter "status=exited" | ForEach-Object -Process {docker rm $_}

Resize disk space for docker vm

> docker-machine create --driver hyperv --hyperv-disk-size "40000" default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment