Skip to content

Instantly share code, notes, and snippets.

@mtfelian
Created January 12, 2023 09:56
Show Gist options
  • Save mtfelian/6bd24327b69d30f7d0d3c5000747f01e to your computer and use it in GitHub Desktop.
Save mtfelian/6bd24327b69d30f7d0d3c5000747f01e to your computer and use it in GitHub Desktop.
PS script to stop all containers except the given list
$containersToKeep = @("postgis")
$runningContainers = docker ps -q
foreach ($container in $runningContainers) {
$containerName = (docker inspect --format "{{.Name}}" $container).TrimStart('/')
if ($containersToKeep -contains $containerName) {
continue
}
Write-Host "Stopping container $container ($containerName)"
docker stop $container
Write-Host "Removing container $container ($containerName)"
docker rm $container
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment