Listing and Inspecting Docker Containers
After creating and running Docker containers, it's important to be able to list and inspect them to understand their status, configuration, and behavior. In this section, we'll explore the various commands and techniques for managing and inspecting Docker containers.
Listing Docker Containers
To list all the Docker containers on your system, you can use the docker container ls
command. This will display a table with information about the running containers, including the container ID, image, command, creation time, status, and ports.
docker container ls
If you want to see all containers, including those that are not running, you can use the -a
or --all
flag:
docker container ls -a
Inspecting Docker Containers
To get more detailed information about a specific container, you can use the docker container inspect
command. This command will return a JSON-formatted output with a wealth of information about the container, including its configuration, network settings, and resource usage.
docker container inspect <container_id>
You can also use the --format
flag to extract specific information from the inspection output. For example, to get the IP address of a container:
docker container inspect --format '{{.NetworkSettings.IPAddress}}' <container_id>
Monitoring Docker Containers
To monitor the real-time activity and resource usage of a Docker container, you can use the docker container stats
command. This command will display a live stream of information about the container's CPU, memory, network, and I/O usage.
docker container stats <container_id>
By understanding how to list, inspect, and monitor Docker containers, you'll be better equipped to manage and troubleshoot your application infrastructure, ensuring optimal performance and resource utilization.