问题描述
有没有什么方法来确定是否一个进程(脚本)的LXC容器(〜泊坞窗运行时)内运行?我知道有些程序能够检测它们是否在虚拟机中运行,是类似的东西可供LXC /泊坞窗?
Is there any way to determine if a process (script) runs inside an lxc container (~ Docker runtime)? I know that some programs are able to detect whether they run inside a virtual machine, is something similar available for lxc/docker?
推荐答案
最可靠的方法是检查的/ proc / 1 / cgroup中
。它会告诉你init进程的对照组,而当你的不的容器中,这将是 /
所有层次。当你的在的容器,你会看到锚点的名称;其中,与Docker容器,会像 / LXC /< containerid方式>
The most reliable way is to check /proc/1/cgroup
. It will tell you the control groups of the init process, and when you are not in a container, that will be /
for all hierarchies. When you are inside a container, you will see the name of the anchor point; which, with Docker containers, will be something like /lxc/<containerid>
.
这篇关于确定一个过程LXC /泊坞窗内运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!