Original link: https://blog.frytea.com/archives/775/
To determine if the currently running terminal is inside a Docker container, you can examine container-specific files and environment variables. Here’s one way, judging by looking at the /proc/1/cgroup file:
cat /proc/1/cgroup
Observe the content of the output. If you see something related to Docker such as docker or containerd, you are currently running inside a Docker container. For example:
12:memory:/docker/9a3c3b3d3e3c413dc3f3e3g3h3i3j3k3l3m 11:devices:/docker/9a3c3b3d3e3c413dc3f3e3g3h3i3j3k3l3m ...
If the output doesn’t mention Docker or a similar container technology, then you’re probably not running inside a Docker container.
Note that this approach works primarily with Docker containers, not necessarily with other container technologies (like Podman, LXC, 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/775/
This site is only for collection, and the copyright belongs to the original author.