Check the value of the "container" environment variable: - "lxc" indicates a LXC container - "systemd-nspawn" indicates a systemd nspawn container
Detect Docker by: - Presence of .dockerenv file. - Finding "docker" in /proc/1/cgroup Detect LXC by: - Finding "lxc" in /proc/1/cgroup