You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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:

1. One-Liner Command (Works in CMD & PowerShell)

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)
2. PowerShell Script (For More Visibility)

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.

3. CMD-Specific One-Liner

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 .bat or .cmd script, replace %i with %%i to 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 -aq flag lists all container IDs, including stopped ones).

内容的提问来源于stack exchange,提问作者Issa Fram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:26:19