Original link: https://blog.frytea.com/archives/774/
To determine if the currently running system is inside an LXC container, certain environment variables and files can be checked. Here’s one way, judged by looking at the /proc/1/environ file:
Run the following command in a terminal:
cat /proc/1/environ | tr '\0' '\n' | grep '^container='
Observe the content of the output. If the output contains container=lxc, you are currently running inside an LXC container. For example:
container=lxc
If the output is empty, then you’re probably not running inside an LXC container.
Another way is to check the /proc/1/cgroup file, similar to how you check a Docker container:
cat /proc/1/cgroup
Observe the content of the output. If you see something related to LXC such as lxc, you are currently running inside an LXC container. For example:
10:memory:/lxc/1234 9:devices:/lxc/1234 ...
Note that these methods apply primarily to LXC containers and not necessarily to other container technologies (such as Docker, Podman, etc.). If you are using another container technology, you may need to find files or environment variables specific to that technology.
This article is transferred from: https://blog.frytea.com/archives/774/
This site is only for collection, and the copyright belongs to the original author.