如何在 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.