Module exposing: InContainer
// Source: https://github.com/initializ/forge | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package security
import "os"
// InContainer returns true when the process runs inside Docker or Kubernetes.
// Used to skip the local egress proxy (NetworkPolicy enforces egress there).
func InContainer() bool {
// Check Kubernetes: KUBERNETES_SERVICE_HOST is always set in pods
if os.Getenv("KUBERNETES_SERVICE_HOST") != "" {
return true
}
// Check Docker: /.dockerenv is created by Docker
if _, err := os.Stat("/.dockerenv"); err == nil {
return true
}
return false
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key