如何在 Docker 中列出容器 [英] How to list containers in Docker

查看:30
本文介绍了如何在 Docker 中列出容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个命令可以列出镜像,docker images,但是好像没有对应的docker容器.

There's a command to list images, docker images, but there doesn't seem to be a corresponding docker containers.

除了成为 root 并查看 /var/lib/docker 之外,似乎没有办法做到这一点.我错过了什么吗?这是不应该做的事情吗?

Other than becoming root and looking into /var/lib/docker there doesn't seem a way to do that. Am I missing something? Is that something one isn't supposed to do?

推荐答案

要仅显示正在运行的容器,请使用给定的命令:

To show only running containers use the given command:

docker ps

要显示所有容器,请使用给定的命令:

To show all containers use the given command:

docker ps -a

要显示最新创建的容器(包括所有状态),请使用给定的命令:

To show the latest created container (includes all states) use the given command:

docker ps -l

要显示 n 个上次创建的容器(包括所有状态),请使用给定的命令:

To show n last created containers (includes all states) use the given command:

docker ps -n=-1

要显示总文件大小,请使用给定的命令:

To display total file sizes use the given command:

docker ps -s

以上内容来自docker.com.

新版Docker更新了命令,增加了一些管理命令:

In the new version of Docker, commands are updated, and some management commands are added:

docker container ls

用于列出所有正在运行的容器.

It is used to list all the running containers.

docker container ls -a

然后,如果你想把它们全部清理干净,

And then, if you want to clean them all,

docker rm $(docker ps -aq)

用于列出所有创建的容器,而不管其状态.

It is used to list all the containers created irrespective of its state.

并停止所有 Docker 容器(强制)

And to stop all the Docker containers (force)

docker rm -f $(docker ps -a -q)  

这里的容器是管理命令.

Here the container is the management command.

这篇关于如何在 Docker 中列出容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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