0

step1:运行一个nginx容器

docker run -d -p 8000:80

step2:通过nsenter检查netowrk dev

nsenter -t $PID -n ip a

控制台打印

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
7: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 2001:db8:1::242:ac11:2/64 scope global nodad
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:2/64 scope link
       valid_lft forever preferred_lft forever

情况1:

但它不能以这种方式工作 nsenter -t $PID -p ps -ef 它打印了我的主机命名空间进程

案例2:

nsenter -t $PID -a ps -ef

nsenter: failed to execute ps: No such file or directory

案例 3:当我附加容器 bash 并安装 ps( docker exec -it $ContainerID bash) 时,它会运行良好。( nsenter -t $PID -a ps -ef)

root@dev:/root# nsenter -t $PID -a ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 12:32 ?        00:00:00 nginx: master process nginx -g daemon off;
nginx         31       1  0 12:32 ?        00:00:00 nginx: worker process
nginx         32       1  0 12:32 ?        00:00:00 nginx: worker process
nginx         33       1  0 12:32 ?        00:00:00 nginx: worker process
nginx         34       1  0 12:32 ?        00:00:00 nginx: worker process
root         536       0  0 13:29 ?        00:00:00 ps -ef

我很困惑。

4

0 回答 0