Docker stats command
outline
docker stats command tutorial
The docker stats command can be used to dynamically display the resource consumption of Docker containers , including: CPU, memory, and network I/O. The docker stats command can also specify stopped containers, but will not return any information.
docker stats command syntax
haicoder(www.haicoder.net)# docker stats [options] [container...]
docker stats command parameters
parameter | describe |
---|---|
–all, -a | View all container information (running ones are displayed by default). |
–format | Go templates display image information. |
–no-stream | Do not display some dynamic information of the container. |
the case
View non-running container information
Use the docker create -it command to create a dokcer container.
haicoder(www.haicoder.net)# docker create -it --name haicoder centos
15c2fa5be4ed7452aaa3074137cee51cb04a65f281e11ff4cd2246582bb1084c
Use the docker stats command to view information about a specified container.
haicoder(www.haicoder.net)# docker stats haicoder
At this point, the terminal displays the following:
That is, the container's CPU, memory, network I/O and other information are listed at this time, because the container is not running, so no information is output.
Use **docker kill** and docker rm commands to remove all containers.
haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`
View running container information
Use the docker run -it command to run a docker container.
haicoder(www.haicoder.net)# docker run -it -d --name haicoder centos
2afe11f89b4186d506e7eb8388a0f3369096c187ca215f3038b89f5caae5203b
Use the docker stats command to view information about running containers.
haicoder(www.haicoder.net)# docker stats haicoder
At this point, the terminal displays the following:
CPU
That is, the container , memory, network I/O and other information are output at this time . Finally, we use the docker kill and docker rm commands to remove all containers.
haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`
View all container information
Using the docker run -it command, run three dokcer containers.
haicoder(www.haicoder.net)# docker run -it -d --name haicoder centos
f0f5905fb275ed3a08ffb710b9fb7be2215583dd4e9be049d84ed9d31af187ee
haicoder(www.haicoder.net)# docker run -it -d --name coder centos
660a8181fc6f9a0009fe1dff864e19acee4a104273a55cdb5f5e0758d9a5fc90
haicoder(www.haicoder.net)# docker run -it -d --name HaiCoder centos
234b0947938a066c8c48c78ac0908957911f5d010cd80de49c98969a4f5487df
Use the docker stats --all command to view information about all containers.
haicoder(www.haicoder.net)# docker stats --all
At this point, the terminal displays the following:
That is, the CPU, memory, network I/O and other information of all containers are output at this time. Finally, we use the docker kill and docker rm commands to remove all containers.
haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`
Only display static information
Using the docker run -it command, run three dokcer containers.
haicoder(www.haicoder.net)# docker run -it -d --name haicoder centos
aed677bcde2844cf8794eb14da6506ae8550fbe550c7ba0d6c3efcdf15247e6e
haicoder(www.haicoder.net)# docker run -it -d --name coder centos
a3515ce1d54de257099dc3f16e93aeed1994ab586f5a9933ce15842785c5665a
haicoder(www.haicoder.net)# docker run -it -d --name HaiCoder centos
768ac03fbb6e44f0a10365eaa7669dd571ce2aa8181e2934793dde83391242d4
Use the docker stats command to view only the static information of the container.
haicoder(www.haicoder.net)# docker stats --no-stream
At this point, the terminal displays the following:
That is, the CPU, memory, network I/O and other information of all containers are output at this time, but it is not in a dynamic form, but only the latest information is displayed.
Use the docker kill and docker rm commands to remove all containers.
haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`
docker stats command output
output | describe |
---|---|
CONTAINER | Displays the ID of the container in short format. |
CPU % | CPU usage. |
MEM USAGE / LIMIT | The currently used memory and the maximum available memory. |
MEM % | Displays memory usage as a percentage. |
NET I/O | Network I/O data. |
BLOCK I/O | Disk I/O data. |
PIDS | PID number. |
docker stats command summary
The docker stats command can be used to dynamically display the resource consumption of Docker containers, including: CPU, memory, and network I/O.
The docker stats command can also specify stopped containers, but will not return any information.
The docker stats command uses the --all parameter to list information about all containers. The docker stats command uses the --no-stream parameter to view only the static information of the container.