如何在Docker中列出容器 [英] How to list containers in Docker
问题描述
有一个列出图像的命令, docker图像
,但似乎没有相应的 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
要显示总计文件大小使用给定命令:
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)
此处容器是管理命令。
这篇关于如何在Docker中列出容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!