ppkarwasz commented on PR #1323: URL: https://github.com/apache/commons-lang/pull/1323#issuecomment-2508936863
Hi @maxxedev, Since container detection is pretty much heuristic, I think that we should mimic the code of projects that **really** need to know if they are running in a container and put a link to that project in a comment, so we can follow its evolution. The best reference I found is [`detect_container` in the `virt.c` source of SystemD](https://github.com/systemd/systemd/blob/main/src/basic/virt.c). For SystemD it is essential to know if it is running in a container, so we could follow its code to the letter. IMHO the overall logic of `inContainer()` should be: 1. We check the `container` environment variable of process `1` as an **opt-in** way for container developers to declare the type of container: - If the variable is **empty**, we return `false`. This includes the case, where the container developer wants to hide the fact that the application runs in a container. - If the variable is **not** empty, we return `true`. - If the variable is **absent**, we continue. 2. We check files in the container. According to SystemD: - `/.dockerenv` is used by Docker. - `/run/.containerenv` is used by PodMan. - I would ignore other files (e.g. `/var/run/.containerenv`) or first make a PR for SystemD and if they accept it, use it in Commons Lang. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
