How to determine if a process runs inside lxc/Docker?

后端 未结 16 1356
情歌与酒
情歌与酒 2020-11-28 18:15

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 v

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 19:06

    My answer only applies for Node.js processes but may be relevant for some visitors who stumble to this question looking for a Node.js specific answer.

    I had the same problem and relying on /proc/self/cgroup I created an npm package for solely this purpose — to detect whether a Node.js process runs inside a Docker container or not.

    The containerized npm module will help you out in Node.js. It is not currently tested in Io.js but may just as well work there too.

提交回复
热议问题