Detect container

You can’t really do that, but you can check some facts in the environment which can indicate the process is running in a container. Even if you do that, it could be different everywhre. As I suggested in this topic

I recommend setting an environment variable as you would when running systemd in a container or check whether you can do something in the environment or not.

You can also find this link in the mentioned topic:

The user in the other topic opened this issue as I suggested, but I suspected what the answer would be. The issue was closed and a project member basically suggested what I did.