The docker top command

You can run the top command from the Docker host machine using the following command:

docker top [OPTIONS] CONTAINER [ps OPTIONS]  

This gives a list of the running processes of a container without logging in to the container, as follows:

$ sudo docker top  a245253db38b
UID PID PPID C
STIME TTY TIME CMD
root 5232 3585 0
Mar22 ? 00:00:53 python app.py
$ sudo docker top a245253db38b -aef
UID PID PPID C
STIME TTY TIME CMD
root 5232 3585 0
Mar22 ? 00:00:53 python app.py

The Docker top command provides information about the CPU, memory, and swap usage if you run it inside a Docker container:

root@a245253db38b:/opt/webapp# top
top - 19:35:03 up 25 days, 15:50, 0 users, load average: 0.00, 0.01, 0.05
Tasks: 3 total, 1 running, 2 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1016292k total, 789812k used, 226480k free, 83280k buffers
Swap: 0k total, 0k used, 0k free, 521972k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM
TIME+ COMMAND

1 root 20 0 44780 10m 1280 S 0.0 1.1 0:53.69 python
62 root 20 0 18040 1944 1492 S 0.0 0.2 0:00.01 bash
77 root 20 0 17208 1164 948 R 0.0 0.1 0:00.00 top

In case you get the error - TERM environment variable not set error while running the top command inside the container, perform the following steps to resolve it:

Run the echo $TERM command. You will get the result as dumb. Then, run the following command:

$ export TERM=dumb 

This will resolve the error.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset