在Windows上一次停止所有Docker容器

编程入门 行业动态 更新时间:2024-10-24 12:26:58
本文介绍了在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 或 Windows版Bash 中,您可以使用以下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容器

本文发布于:2023-11-09 10:16:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572111.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   Windows   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!