Created
January 12, 2023 09:56
-
-
Save mtfelian/6bd24327b69d30f7d0d3c5000747f01e to your computer and use it in GitHub Desktop.
PS script to stop all containers except the given list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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