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

查看:29
本文介绍了如何确定进程是否在 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//docker/.

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天全站免登陆