如何确定进程是否在lxc/Docker中运行? [英] How to determine if a process runs inside lxc/Docker?

查看:91
本文介绍了如何确定进程是否在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆