Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
CompTIA Linux+ XK0-005 - 3.2 - Container Management: Listing
Listing containers is an essential task in Docker container management. It allows you to view the containers running on your system, along with their essential details such as container names, IDs, status, and more. This guide will provide an overview of listing containers and demonstrate different techniques to list containers using the docker ps
and docker container ls
commands.
Listing Containers
There are multiple commands available to list containers in Docker. Let's explore some commonly used options and examples:
List Running Containers
To list the running containers on your system, you can use the docker ps
or docker container ls
commands:
docker ps
# OR
docker container ls
Example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc123456789 nginx:latest "nginx -g ..." 2 hours ago Up 2 hours 80/tcp my-nginx
def987654321 mysql:latest "mysqld" 3 days ago Up 3 days 3306/tcp my-mysql
List All Containers
To list all containers, including running and stopped ones, you can use the -a
or --all
option with the docker ps
or docker container ls
commands:
docker ps -a
# OR
docker container ls -a
Example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc123456789 nginx:latest "nginx -g ..." 2 hours ago Up 2 hours 80/tcp my-nginx
def987654321 mysql:latest "mysqld" 3 days ago Exited (137) 3 days ago 3306/tcp my-mysql
xyz789012345 redis:latest "redis-serve" 1 week ago Exited (0) 1 week ago 6379/tcp my-redis
Filter Containers by Name
You can filter the listed containers by name using the --filter
option. For example, to list containers with a specific name, use the following command:
docker ps --filter "name=my-container"
# OR
docker container ls --filter "name=my-container"
Example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc123456789 nginx:latest "nginx -g ..." 2 hours ago Up 2 hours 80/tcp my-container
Conclusion
Listing containers in Docker is an essential operation for managing and monitoring your containers. By using commands like docker ps
and docker container ls
with various options, you can effectively view and filter containers based on your requirements.
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.