如何在Docker中列出容器
There's a command to list images, docker images , but there doesn't seem to be a corresponding dock
本文翻译自:How to list containers in Docker
There's a command to list images, docker images
, but there doesn't seem to be a corresponding docker containers
. 有一个命令可以列出镜像, docker images
,但是似乎没有相应的docker containers
。
Other than becoming root and looking into /var/lib/docker
there doesn't seem a way to do that. 除了成为root并查看/var/lib/docker
,似乎没有其他方法可以做到。 Am I missing something? 我想念什么吗? Is that something one isn't supposed to do? 那是不应该做的事情吗?
#1楼
参考:https://stackoom.com/question/18exV/如何在Docker中列出容器
#2楼
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
To show n last created containers (includes all states) use the given command: 要显示n个最后创建的容器 (包括所有状态),请使用给定命令:
docker ps -n=-1
To display total file sizes use the given command: 要显示总文件大小,请使用给定命令:
docker ps -s
The content presented above is from docker.com . 上面显示的内容来自docker.com 。
In the new version of Docker, commands are updated, and some management commands are added: 在新版本的Docker中,命令已更新,并添加了一些管理命令:
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. 它用于列出所有创建的容器,无论其状态如何。
And to stop all the Docker containers (force) 并停止所有Docker容器(强制执行)
docker rm -f $(docker ps -a -q)
Here the container is the management command. 这里的容器是管理命令。
#3楼
Note that some time ago there was an update to this command. 请注意,前段时间对该命令进行了更新。 It will not show the container size by default (since this is rather expensive for many running containers). 默认情况下,它不会显示容器的大小(因为这对于许多正在运行的容器来说是相当昂贵的)。 Use docker ps -s
to display container size as well. 使用docker ps -s
可以显示容器大小。
#4楼
docker ps -s will show the size of running containers only. docker ps -s将仅显示正在运行的容器的大小。
To check the size of all containers use docker ps -as
要检查所有容器的大小,请使用docker ps -as
#5楼
To list only the containers SHA1: 仅列出容器SHA1:
docker ps -aq --no-trunc
That way, you can use the list of all containers for other commands (which accept multiple container ids as parameters). 这样,您可以将所有容器的列表用于其他命令(这些命令接受多个容器ID作为参数)。
For example, to list only the name of all containers (since docker ps
list only their names with other information): 例如, 仅列出所有容器的名称 (因为docker ps
仅列出其名称以及其他信息):
docker inspect --format='{{.Name}}' $(sudo docker ps -aq --no-trunc)
#6楼
I got the error message Cannot connect to the Docker daemon.
我收到错误消息Cannot connect to the Docker daemon.
I forgot I am running the daemon as root and needed sudo
: 我忘了我以root身份运行守护进程,并且需要sudo
:
$ sudo docker ps
更多推荐
所有评论(0)