systemd-detect-virt
Detect execution in a virtualized environment. tldr-pages
On Linux
Linux
List detectable virtualization technologies
systemd-detect-virt --listIdentifyDetect virtualization, print the result, and return a zero status code when running in a VM or a container, and a non-zero code otherwise
systemd-detect-virtIdentifySilently check without printing anything
systemd-detect-virt --quietIdentifyOnly detect container virtualization
systemd-detect-virt --containerIdentifyOnly detect hardware virtualization
systemd-detect-virt --vmIdentifyDetect whether in a chroot environment
systemd-detect-virt --chrootIdentify