I am looking for a simple but reliable way to detect from shell (bash) if is running inside a container or not, regardless if that container happens to be run under docker, lxc, pods,...
I need this in order to perform to gather to collect output of systemctl status "*"
. Mainly I want to avoid a noisy failure like Failed to get D-Bus connection: Operation not permitted
which will almost for sure happen inside containers.
The desired outcome is to return success and no output when inside containers and to run systemctl in the other cases.
There are several similar questions but I found none that works in this use case, most of the answers are few years old and they just do fail to deliver.