Package virt
is a library that helps detect if application is running in a
virtual machine, container or bare-metal.
It depends on klauspost/cpuid library for getting low-level CPU flags.
Detection mechanism is based on the checks in chuckleb/virt-what.
go get -u github.com/sewiti/virt
package main
import (
"fmt"
"github.com/sewiti/virt"
)
func main() {
fmt.Println("Virtual machine: ", virt.IsVM())
fmt.Println("Container: ", virt.IsContainer())
}