Docker Community Forums

Share and learn in the Docker community.

Processes running inside the container are visible outside the container on host machine?

Hello,

I have my docker container running on ubuntu-20.04 machine. Many processed are running inside the container. On running “top” and “ps” command inside the container I can see the processes running inside the container with specific PID.

If I use the “ps” commands (for any process running inside the container) on host i.e outside the container I could see the processes running inside the container but with different PIDs. It looks something like those processes are running on my host machine. And, If I stop my container and check with the “ps” command then the process will also disappear on host machine.

I am not understanding how and why does this is happening actually. Hoe really the processes inside the container are mapped? Is this really normal to see the process outside the container with different PID?

On using “ps -eaf” command I could see all the processes that are running inside the conrtainers are being shown on the host machine with username "root"

$: ps -eaf

on host machine:
image

#: ps -eaf

inside the container

sh-4.4# ps -eaf
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 07:27 ?        00:00:00 ping localhost
root          37       0  0 08:16 pts/0    00:00:00 sh
root          52       1 17 08:18 ?        00:01:42 [stress] <defunct>
root          62       0  0 08:27 pts/1    00:00:00 sh
root          68      62  0 08:27 pts/1    00:00:00 /bin/bash ./test_MEM_CPU.sh
root          77      68  0 08:28 pts/1    00:00:00 stress -c 1 --vm-keep --timeout 120s
root          81      77 79 08:28 pts/1    00:00:04 stress -c 1 --vm-keep --timeout 120s
root          83      37  0 08:28 pts/0    00:00:00 ps -eaf

Here we could see that same processes both inside the container and on host machine but with different PID. Is container really performing the virtualization here?

Can anybody help me on understanding this scenario? Any inputs will help me a lot.

Regards,
Siddhartha V

Hi

Yes this is quite normal, the pid inside the container, or, atleast the MAIN pid will always be 1.
But since docker uses the kernel on the host, and not its own, you will see it in ps command on the host.

Hello @terpz

Thank you for the reply. It is useful info. May I know where can I get detailed info to read the entire docker container structure and process details please. I googled it but I couldn’t get the specific data so your inputs will help me.

Also, how can I study the file system of a docker container? For example If create a container image then where can I find it locally? how can I study its file system and file format?

Regards,
Siddhartha V

Not sure about the documentation about this.

All docker related files are located (Default) in /var/lib/docker

hello @terpz ,

ok thank you. Actually my question is using “docker image list” we will get the list of all the docker images. But I need to find them locally in my host I need to inspect them. Is it possible?

Yes, its in /var/lib/docker.

You can use: docker image inspect image:tag to see its info

1 Like