本文介绍了在 Windows 上一次停止所有 docker 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何停止在 Windows 上运行的所有 docker 容器?
How can I stop all docker containers running on Windows?
docker stop 仅适用于 1 个容器.
docker stop is for 1 container only.
有什么命令/脚本可以让它停止所有容器吗?
Any command/script to make it stop all containers?
推荐答案您可以创建一个批处理文件(.bat 或 .cmd>) 里面有这些命令:
You could create a batch-file (.bat or .cmd) with these commands in it:
@ECHO OFF FOR /f "tokens=*" %%i IN ('docker ps -q') DO docker stop %%i如果你想直接在控制台运行这个命令,把%%i替换成%i,比如:
If you want to run this command directly in the console, replace %%i with %i, like:
FOR /f "tokens=*" %i IN ('docker ps -q') DO docker stop %i在 Git Bash 或 Bash for Windows 中,您可以使用以下 Linux 命令:
In Git Bash or Bash for Windows you can use this Linux command:
docker stop $(docker ps -q)注意:如果没有容器在运行,这将失败
对于 PowerShell,命令与 Linux 非常相似:
For PowerShell, the command is very similar to the Linux one:
docker ps -q | % { docker stop $_ }更多推荐
在 Windows 上一次停止所有 docker 容器
发布评论