The other answers don't seem to provide an easy way to delete just the containers with "auto-generated" names. This is my most frequent intent, so I wrote a Powershell script for it:
$containers = (docker container list -a).Split("`n") | % { [regex]::split($_, "\s+") | Select -Last 1 }
$containersToRemove = $containers | Where { ([regex]"^[a-z]+_[a-z]+$").IsMatch($_) }
# it's recommended to delete in batches, as too many at once can cause issues
$containersToRemove = $containersToRemove | Select-Object -First 30
foreach ($container in $containersToRemove) {
# sync/wait-based version (slow)
# docker container rm $container
# async/background-process version (fast)
Start-Process -FilePath docker -ArgumentList "container rm $container" -NoNewWindow
}
Take caution of course, as this script is just using a regular-expression: ^[a-z]+_[a-z]+$
So only use it if you know that the containers you care about do not use the same format (of lowercase-word, underscore, lowercase-word); or at least only run the first two lines, run echo $containersToRemove
, and check the list before actually executing the deletions.
docker images purge
--> will remove all your docker imagesdocker image ls -q | xargs -I {} docker image rm -f {}
docker image prune
(image is singular and it's prune instead of purge).docker image prune --all --force