-2

I have a process running inside a container. I want to know this process's pid in docker host namespace from inside the container. I have a docker client installer inside the container from which I can execute a few commands but I do not have full privileges since I'm doing so from inside the container. Is there a way to find this pid?

Ru2ja
  • 1
  • 4
  • ps -eaf is not working? – Naresh Joshi May 23 '17 at 05:18
  • @NareshJoshi ps -eaf would give me pid in the namespace in which it is executed. e.g. from run inside the container, it would give pid specific to that container namespace. I want to get pid in docker host namespace from inside the container. – Ru2ja May 23 '17 at 05:30
  • What is your goal? The container is supposed to be isolated from the host – user2915097 May 23 '17 at 05:31
  • The goal is to make sure that only one instance of a process is running at time on a docker host. So the idea is to store the pid of the process at docker host level, so that it can be checked before starting a new instance. The problem I'm facing is that the pid is different for the process at docker host and at container level. So, I want to get pid at docke host level but I can do so only from inside the container. I have access to docker for this purpose. – Ru2ja May 23 '17 at 05:38
  • see also https://stackoverflow.com/questions/39931316/what-is-the-pid-in-the-host-of-a-process-running-inside-a-docker-container – user2915097 May 23 '17 at 06:42
  • @user2915097 I checked the link mentioned above. As per the answer in there, in order to find the mapping between pid at container and pid at host, you have to check the status file at docker host. That won't work in my case since I have limitation of executing this from inside the container and with limited privileges inside the container, I will not be allowed to check the status file. – Ru2ja May 23 '17 at 06:59
  • Docker is not the right tool for waht you want to do. Docker is about isolation, isolating container from the host. The host can access anything in a container, the container can't access the host, but may have access to some volume, data, environment variable that give some information about the host, as long as the host allows it. – user2915097 May 23 '17 at 13:47

1 Answers1

-1

The purpose of this approach was to make sure that only one instance of a process is running at time on a docker host. So the idea is to store the pid of the process at docker host level, so that it can be checked before starting a new instance. I found another way to do so by using container id. You can do docker ps from inside the container and it will list all the containers running on docker host. Moreover container id does not change with namespace unlike pid. That solves my problem.

Ru2ja
  • 1
  • 4