List a docker container
Sometimes, rather than focusing on what you are going to do next is not so important but checking and making sure that what you have already created is right and is it up and running smoothly. Docker is no exception, in real production environments it is necessary to make sure that the container is up and running perfectly and in order to do that we must know to list a docker container.
Note: Before going further make sure you know basics of docker.
Show running containers
Running the command as shown below will let you see the running containers:
sudo container ls
Question: What if we want to see the stopped containers as well?
Answer: To do so, follow the next section of this post.
Show stopped containers
Question: So, what are stopped containers?
Answer: Sometimes, we stop a container because of some technical reasons and a few times due to some testing reasons.
In order to see the stopped containers, we need to add some arguments to the normal listing container command, as shown below:
sudo container ls -a
-a = show all the containers, including the stopped ones
Learn how to create your first container
Show only the container ID’s
We can also see only the container ID’s and avoid the cluttered information, and to do follow:
Note: Below command is only going to show the running containers but in
sudo docker container ls -q
-q = it states that show containers with only the ID’s or shows the output of the command in quiet manner.
Note: Below command is going to show th
sudo docker container ls -a -q
-a = show the container’s ID
–q = output of command in quiet mode
In this post, we have learnt about listing of docker containers in all the possible ways, and they are surely going to help in more complex situations while working on real life problems in production environments.