确定一个过程LXC /泊坞窗内运行 [英] Determining if a process runs inside lxc/Docker

查看:103
本文介绍了确定一个过程LXC /泊坞窗内运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么方法来确定是否一个进程(脚本)的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 /泊坞窗内运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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