如何确定进程是否在lxc/Docker中运行? [英] How to determine if a process runs inside lxc/Docker?
问题描述
是否有任何方法可以确定进程(脚本)是否在lxc容器(〜Docker运行时)中运行?我知道有些程序能够检测它们是否在虚拟机中运行,是否可以为lxc/docker使用类似的程序?
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进程的控制组,并且当您不在容器中时,所有层次结构都将为/
.当您位于容器中时,将看到锚点的名称.使用LXC/Docker容器,它们分别类似于/lxc/<containerid>
或/docker/<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. With LXC/Docker containers, it will be something like /lxc/<containerid>
or /docker/<containerid>
respectively.
这篇关于如何确定进程是否在lxc/Docker中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!