List Docker containers

Published: November 14, 2022

List Docker containers

In this article, we cover how to list Docker containers. Just like we have ls command in Ubuntu to list contents of our directory. We can also list Docker containers as well.

List Docker containers

Use follow command to list Docker containers -

docker container ls

It shows us data of running containers. The output from the above command is divided in seven fields - CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS and NAMES. Though the output isn't restricted to only these fields. There could be more like SIZE field (covered later in the article) which come up when we use certain options along-with it.

We start with CONTAINER ID first. It is same as that of hostname of our Container. Docker randomly assigns a unique ID to a container.

IMAGE - It shows us the name of Docker image through which we run a container.

COMMAND - the command which executes a process in the container.

CREATED - shows how much time has passed since the container was created.

STATUS - current status of the container. For instance - Exited, Up etc.

PORTS - connected container ports.

NAMES - container's name.

As already mentioned, the above command - docker container ls shows us a list of running containers. But, what about those which we have previously exited? To get data of all containers irrespective of their status, we use -a option,

docker container ls -a

To list only the CONTAINER ID's of all containers -

docker container ls -a -q

This one is pretty useful, to display total file size of a container then use -s option,

docker container ls -s

To show only latest created container -

docker container ls -l

In conclusion, we have covered how to list Docker containers. In next article, we cover how to filter containers on the basis of a condition.