2015年9月20日 星期日

[ 常見問題 ] Determining if a process runs inside lxc/Docker

Source From Here 
Question 
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? 

How-To 
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/. For example: 
# cat /proc/1/cgroup | grep cpu: // In Host
3:cpu:/
# docker ps -q // We have one container running with below id
e1860d7986dd
# docker exec e1860d7986dd cat /proc/1/cgroup | grep cpu:
3:cpu:/docker/e1860d7986dd5116fc18bc71e424b566a64b727d340ece316e128ce59e44d103

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...