Run a process without actually execing into a container using nsenter

645 Views Asked by At

Details

I wanted to run a process on a container without actually execing into it. This is because the container might not have all the packages installed to run the commands. Like if I want to run a stress command then I might not found stress in the container and have to install it separately.

I checked few possibilities to do this and I found one way is using nsenter.

Issue

I have an Nginx container on which I want to run the stress process without actually execing into it.

  • I fetched the pid of the container (which was 1212) and tried to run the following commands:
# nsenter -t 1212 -i -p -n -u
# hostname
nginx-86c57db685-q47lq

I checked I was getting the correct hostname. But if I use -m or -r option then I'm getting.

# nsenter -t 1212 -i -p -n -u -m -r
nsenter: failed to execute /bin/sh: No such file or directory

Now if I run a stress process on it:

# nsenter -t 1212 -i -p -n -u
# stress-ng -c 2
stress-ng: info:  [50] defaulting to a 86400 second (1 day, 0.00 secs) run per stressor
stress-ng: info:  [50] dispatching hogs: 2 cpu

It does not give a cpu spike to the target container having container id 1212 instead it hog the same host.

So, Is there a way to run a process like stress or dd on a target container without running exec command? I was also trying to check cgexec and cgroups for this.

0

There are 0 best solutions below