我在 docker 容器中运行一个 node.js 应用程序(因为我无法在我们的机器上安装 node(。我的应用程序使用系统信息包来获取 CPU 利用率,但这是 docker 容器的 CPU 利用率。我希望主机上运行的进程的 CPU 利用率。
这能做到吗?
使用主机的 PID 命名空间和--pid=host
选项来docker run
。
从手册页:
--pid="" Set the PID mode for the container Default is to create a private PID namespace for the container 'container:<name|id>': join another container's PID namespace 'host': use the host's PID namespace for the container. Note: the host mode gives the container
完全访问本地 PID,因此被认为是不安全的。