如何在Windows系统中一次性停止所有Docker容器?
Hey there! Stopping all running Docker containers at once on Windows doesn’t have to be a tedious one-by-one task. Here are a few reliable methods to get this done quickly, depending on the shell you’re using:
The simplest way is to combine docker ps (to list running containers) with docker stop. The -q flag for docker ps outputs only the container IDs, which we can pass directly to docker stop:
docker stop $(docker ps -q)
Note: If you’re using PowerShell and run into issues with the above syntax, you can use the pipeline version instead:
docker ps -q | ForEach-Object { docker stop $_ }
This command sends a graceful stop signal to every running container. If you need to force-stop unresponsive containers (similar to pulling the plug), replace docker stop with docker kill:
docker kill $(docker ps -q)
If you want to add feedback or checks (like confirming there are running containers before proceeding), a small PowerShell script works great:
# Fetch IDs of all running containers $runningContainers = docker ps -q if ($runningContainers) { Write-Host "Found $(($runningContainers).Count) running containers. Stopping them now..." docker stop $runningContainers Write-Host "✅ All running containers have been stopped successfully!" } else { Write-Host "ℹ️ No running containers detected—nothing to stop." }
Just save this as Stop-AllDockerContainers.ps1, right-click and run it with PowerShell, or execute it directly from the PowerShell prompt.
If you’re strictly using Command Prompt (CMD) and the first one-liner doesn’t work, use this loop instead:
for /f "tokens=*" %i in ('docker ps -q') do docker stop %i
Tip: If you’re putting this in a
.bator.cmdscript, replace%iwith%%ito avoid syntax errors.
Quick Notes:
- Stopping containers won’t delete any of your data—volumes, images, and container data will remain intact unless you explicitly delete them.
- If you ever need to start all stopped containers later, you can use
docker start $(docker ps -aq)(the-aqflag lists all container IDs, including stopped ones).
内容的提问来源于stack exchange,提问作者Issa Fram

