5

I'm using Docker and would like to identify which processes are running on containers. So, I run this command on my container, which will uses nearly 100 % CPU.

md5sum /dev/urandom

After that I've checked processes using htop on host machine.

enter image description here

How can I identify, that this command is running inside a container instead of host?

3 Answers3

2

You should be able to add the cgroup column which identifies the container the process is running under.

  • Press F2
  • Setup
  • Columns
  • Choose CGROUP
  • Press F10 to save
Mitch
  • 21,223
  • 6
  • 63
  • 86
  • Under cgroup: `system.sli` What does it mean? –  Oct 21 '15 at 18:41
  • That sounds like the start to `system.slice/something`. Your column is probably too narrow to see the entire thing. It may be something like `system.slice/docker-462783dd81f9515dc2a9adf9c2e767559c3d2dbe6a38e45e705d144000f61362.scope` which would be a docker `cgroup`, or it could be `system.slice/NetworkManager.service` which is not. – Mitch Oct 21 '15 at 18:48
  • Is there any method to see all the columns in max width and first of all to save column settings. After `Ctrl+C` everything is default. –  Oct 21 '15 at 18:55
0

As mentioned in "Docker Processes Shown on Host Process List", you can also run top then press shift+f and select the nsPID and nsUSER

The nsPID should match docker inspect --format='{{ .State.Pid }}' <acontainer>
(as in this example, inspired by the pipework script)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I see number like this under `nsPID`: `4026532234` It is different from host process numbers, but where this number comes from? –  Oct 21 '15 at 18:45
  • " It is different from host process numbers" yes, it is not an host process id (different namespace), but you should find the same number when inspecting a container. – VonC Oct 21 '15 at 18:48
  • That is okay, but should I manually inspect all the containers looking after this number? –  Oct 21 '15 at 18:53
  • @mum007 that is the idea (should be made into a script) – VonC Oct 21 '15 at 18:53
  • Now I have only 1 container, so I try to use `inspect` to find this number. Which row should contains it? –  Oct 21 '15 at 18:57
  • @mum007 what output do you get? – VonC Oct 21 '15 at 19:36
  • @mum007 `docker inspect --format='{{ .State.Pid }}' ` should only give you one value, in your case: 5464 – VonC Oct 21 '15 at 20:09
  • 1
    @mum007 that doesn't match the nsPID, but should match one of your processes, as shown in http://unix.stackexchange.com/a/216619/7490 and http://stackoverflow.com/a/26763450/6309 – VonC Oct 21 '15 at 20:16
  • Thanks for this easy solution! –  Oct 21 '15 at 20:38
0

Another option would be to run a command on the container:

docker exec <container> ps ax

This should list the processes running in the container.

Docker Exec Reference

D-rk
  • 5,513
  • 1
  • 37
  • 55