Skip to content

Latest commit

 

History

History
88 lines (55 loc) · 1.91 KB

40_stats.md

File metadata and controls

88 lines (55 loc) · 1.91 KB

Get Stats on Running Containers

Docker Documentation References:

docker stats

docker run

docker stop

docker rm

Intent

The intent of this exercise is to understand how to get live streaming stats from the containers running in docker.

Overview

In this exercise we will start a container and then ask the Docker Engine to display stats about that container. Then we will stop and remove the container.

Kata Steps

Start a container

Command

docker run -d nginx:alpine

Output

/ # docker run -d nginx:alpine
43d08e93f0e8d27d407289c619344311053ffe7f157711678d18b77f7de62f68

Display Stats

Command

docker stats --no-stream

Output

/ # docker stats --no-stream
CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDS
d3e550ecf2b0        0.00%               1.707 MiB / 1.952 GiB   0.09%               508 B / 508 B       0 B / 0 B           2

Stop the container

Command

docker stop $(docker ps -q)

Here we use docker ps to list the ids of all running containers and feed that into docker stop so we don't have to look at or remember the container id or name.

Output

/ # docker stop $(docker ps -q)
d3e550ecf2b0

Remove the container

Command

docker rm $(docker ps -aq)

Output

/ # docker rm $(docker ps -aq)
d3e550ecf2b0

Here we use docker ps to list the ids of all containers and feed that into docker rm so we don't have to look at or remember the container id or name.

Previous | Index | Next