-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check if a process is running inside podman (OCI) container #3586
Comments
One pragmatic way is to check the mount point for E.g.:
If you need to find out what's the podman container ID, you may need to search for that rootfs path in the runtime. E.g. if you think the OCI runtime is runc:
Once you got the ID, you can inspect it with podman:
Or the OCI runtime itself:
|
I use SELinux to check. Tells me processes running in a container, but this does not tell you which container engine launched the container process. grep container=podman /proc/12642/environ |
Assuming we know the PID on the host, we can make a quick lookup via Podman:
The command above prints a list of PIDs of container processes in the host's PID NS. |
From inside container I haven't found references to
|
I see $container set to EDIT: this was on a fedora:31 image |
This can be overridden by images, |
I'm fairly certain that we don't set (Unfortunately, this does mean that it's difficult to rely on the environment variable being set to any specific value - images in particular can override us) |
Correct, container=oci, is being set by some Red Hat images, I believe. |
As it was mentioned on cockpit-project/cockpit#17568 : Merely testing that |
We make a guarantee that the The best check for |
Podman can run images as non-root users, but the process inside is still run as UID 0. This causes issues with the current entrypoint script. This commit attempts to enable support for Podman by checking for artifacts that indicate that it was Podman that started the container. containers/podman#3586 (comment) Solves: #23
I ended up here while reading subscription-manager code that references this issue. So, I will just drop this for the sake of posterity. It turns out that it's not just the Red Hat images that set
I failed to find this in the kickstart files that define the images, so I wonder if it's the build system that's setting them or something else. |
According to the comment, the 'container' environment variable is set to 'podman' when running in a Podman container. containers/podman#3586 (comment)
/kind feature
Description
What is the right way to detect if a process is running inside OCI or podman container? Multiply ways to detect that a process is running in docker container were suggested, including inspecting
/proc/1/cgroup
. As I don't really understand the contents of/proc/1/cgroup
I can not be sure it will work cross-platform.On Fedora 30 from
podman
.Without
podman
.Output of
podman version
:The text was updated successfully, but these errors were encountered: