docker容器中root用户无法查看其它用户运行进程的PID

   

使用Dockerfile构建的容器, 无法看到非root用户运行程序的PID,如下图所示: 

docker为了容器的安全,容器中的root权限有限制,与宿主机上root权限是不一样的,启动容器加上--cap-add=SYS_PTRACE,即可看到PID,官网上也有相关解释。

Runtime privilege and Linux capabilities

--cap-add: Add Linux capabilities
--cap-drop: Drop Linux capabilities
--privileged=false: Give extended privileges to this container
--device=[]: Allows you to run devices inside the container without the --privileged flag.

docker run --privileged时,Docker将拥有访问主机所有设备的权限,这个给的权限太大不安全,不推荐使用。

原文地址:https://www.cnblogs.com/lkj371/p/12883400.html