在 Windows 上一次停止所有 docker 容器 [英] Stop all docker containers at once on Windows

查看:47
本文介绍了在 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 BashBash 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 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆