因为我们要在docker中监控主机,但是默认情况下容器中是看不到主机的进程,也看不到主机的网络的…..
而且,容器中的root其实只是一个普通用户…..
例如:
1 2 3 4 5 6 7 8 9 10 11 |
[root@docker ~]# docker run -it centos Unable to find image 'centos:latest' locally Trying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos 8ba884070f61: Pull complete Digest: sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861 [root@0df145a906bf /]# ps PID TTY TIME CMD 1 ? 00:00:00 bash 13 ? 00:00:00 ps [root@0df145a906bf /]# |
如果想改变这些,我们就需要加入以下特殊的启动参数,我们逐一介绍:
–privileged: 简单理解的话就是能够让容器里边的root变成真正的root,能干root能干的事(比如容器中的root其实是无法执行mount命令的)
–pid=host : 这个选项的功能是让容器能够看到容器外面的主机的世界,也就是能通过ps aux 来查看主机上的进程
–net=host: 这个是禁用了网络隔离,让我们容器共享主机网络,容器的IP地址和主机是一个IP地址
–ipc=host: 这个是允许我们设置一些kernel的参数docker run –sysctl net.ipv4.ip_forward=1 someimage
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021