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

编程入门 行业动态 更新时间:2024-10-24 14:22:07
本文介绍了在 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 容器

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

发布评论

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

>www.elefans.com

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