runningInContainer returns true if we are inside Docker or LXC. It might be prone to false negatives if things change in the future, but likely not false positives.
()
| 1828 | // be prone to false negatives if things change in the future, but likely |
| 1829 | // not false positives. |
| 1830 | func runningInContainer() bool { |
| 1831 | if !build.IsLinux { |
| 1832 | return false |
| 1833 | } |
| 1834 | |
| 1835 | bs, err := os.ReadFile("/proc/1/cgroup") |
| 1836 | if err != nil { |
| 1837 | return false |
| 1838 | } |
| 1839 | if bytes.Contains(bs, []byte("/docker/")) { |
| 1840 | return true |
| 1841 | } |
| 1842 | if bytes.Contains(bs, []byte("/lxc/")) { |
| 1843 | return true |
| 1844 | } |
| 1845 | return false |
| 1846 | } |
no test coverage detected