You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and we can see that e.g. on a Linux host with cgroupsv2 we have:
[root@164502a64991 /]# cat /proc/1/cgroup
0::/
which isn't covered by the above code.
We aren't the only ones who've noticed this discrepancy, as we can see in the linked stack overflow article.
The truth is that detecting containerization isn't very straightforward. For example Puppet's facter seems to only detect docker but not e.g. when running in podman. Issues have also been reported with Chef's Ohai (example) that seem to be resolved. A succinct comment with the possible strategies can be found in benfred/py-spy#614.
As mentioned, there is docker information in /proc/self/mountinfo. Notably, the container ids or hashes. There is a secondary problem which is that some docker containers do not have "/etc/machine-id", "/var/lib/dbus/machine-id", or "/var/db/dbus/machine-id". So the machine-id is also empty.
This code snippet can use mountinfo to get the docker's version of machineid. It can also be re-purposed to indicate if we are in a docker container:
The logic for detecting whether
go-sysinfo
in running inside a container isn't always correct.The code section is:
go-sysinfo/providers/linux/container.go
Lines 48 to 52 in 6057d34
and we can see that e.g. on a Linux host with cgroupsv2 we have:
which isn't covered by the above code.
We aren't the only ones who've noticed this discrepancy, as we can see in the linked stack overflow article.
The truth is that detecting containerization isn't very straightforward. For example Puppet's facter seems to only detect docker but not e.g. when running in
podman
. Issues have also been reported with Chef's Ohai (example) that seem to be resolved. A succinct comment with the possible strategies can be found in benfred/py-spy#614.Ohai's implementation seems to be the most complete, so we could get some ideas from https://github.com/chef/ohai/blob/d63ae8e8af713c44d040f5583aac84cd3d79f9af/lib/ohai/plugins/linux/virtualization.rb#L180-L217
The text was updated successfully, but these errors were encountered: