Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list containers in Docker

Tags:

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?

like image 534
w00t Avatar asked May 30 '13 15:05

w00t


People also ask

What command is use to list all the Docker?

ps -a. List all the docker containers running/exited/stopped with container details.

How do I list all stopped containers?

List Stopped Containers. Stopped containers are those containers that are in exited state. Containers are put into exited state by executing the Docker stop command in them. If you want to list only the stopped containers, you can use the --filter option with a parameter called status.


2 Answers

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 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.

And to stop all the Docker containers (force)

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

Here the container is the management command.

like image 177
vieux Avatar answered Oct 10 '22 23:10

vieux


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` 
like image 20
kramfs Avatar answered Oct 10 '22 22:10

kramfs