Jim
Jim

Reputation: 4395

How can I see the real process inside the container in my host machine?

I start a container in my Mac e.g. docker run -it ubuntu:latest /bin/bash
I can find the pid of /bin/bash from docker inspect but I can not find the real PID of the /bin/bash in my mac.
To give another example:

docker run -it ubuntu:latest /bin/bash  
sleep 2000&  

If I then do in the host machine ps -ef | grep sleep I can not find the sleep process.
I think that in Linux the processes are visible. How does it work on Macs?

Upvotes: 1

Views: 1579

Answers (2)

Dhrubo
Dhrubo

Reputation: 715

You can see the child process within a docker container from Host Linux system if and only if you are running Linux container on Linux Host. No other host will support the child process of container to be visible.

Therefore, considering that you are running a Linux container on Linux then underlying Docker technology directly use linux kernel without creating any virtualized layer. Hence, you will be able to see the child process along with Parent Docker process if you run **top ** command from host.

But, this is not true for Mac or Windows system.Docker technology on these two OS as host operating system is different than Linux. On these platforms, Docker engine/machine creates a separate virtualize layer as Guest Operating system which prevents to listing child process under Docker container.

Nevertheless, we always get into the docker by using docker exec command like @Ivonet tried to answer.

Upvotes: 0

Ivonet
Ivonet

Reputation: 2731

I would say you don't. At least not with ps -ef | grep sleep from the host machine.

This might work:

docker run -it --rm --name coolname ubuntu:latest /bin/bash
sleep 2000&

host machine:

docker exec -it coolname ps -ef | grep sleep

on a Mac you can go a step deeper as docker "native" is actually a minimal linux distro. That image is the actual "shared resource". You can get into that image with a command like screen

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

now if you do the following in a terminal:

docker run -it alpine /bin/sh
sleep 424242&

log in to the native image as described above. You will see the sleep command something like this will be the result:

linuxkit-025000000001:~# ps -ef|grep sleep
 3190 root      0:00 sleep 424242
 3193 root      0:00 grep sleep

so it is actually possible to see the shared resource. So it should also work on Linux but then it might be fully native.

How it works on windows I can't tell :-)

Upvotes: 3

Related Questions