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
.
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
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
The content presented above is from docker.com.
In The New Version Of Docker, Commands Are Update, Some Management Commands Are Added:
docker container ls
Is Used to list all the running containers.
docker container ls -a
Is used to list all the containers created irrespective of its state. Here Container is the management command.
To list all running and stopped containers
docker ps -a
To list all running containers (just stating the obvious and also example use of -f filtering option)
docker ps -a -f status=running
To list all running and stopped containers, showing only their container id
docker ps -aq
To remove all containers that are NOT running
docker rm `docker ps -aq -f status=exited`
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中列出容器?