为什么bashlogin不允许更改docker容器的MTU,但nsenter呢?

我search,但没有find这个查询的答案。 当我尝试通过使用docker exec -it <container id> bash命令进行日志logging来更改容器接口的MTU值时,它不允许我更改接口的MTU值,但是如果使用命令nsenter,则可以更改MTU值。 两者有什么区别?

不工作:当运行bash命令时:

 root@testbp:~# docker exec -it ecd6395e624f bash root@ecd6395e624f:/bp2/src# ip a bash: ip: command not found root@ecd6395e624f:/bp2/src# ifconfig -a eth0 Link encap:Ethernet HWaddr 02:42:ac:10:00:33 inet addr:172.16.0.51 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fddd::33/112 Scope:Global inet6 addr: fe80::42:acff:fe10:33/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1462 Metric:1 RX packets:641487 errors:0 dropped:0 overruns:0 frame:0 TX packets:384426 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:46193582 (46.1 MB) TX bytes:47949234 (47.9 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@ecd6395e624f:/bp2/src# ifconfig eth0 mtu 1450 SIOCSIFMTU: Operation not permitted 

工作:我知道在nsenter中“-n”代表networking名称空间,但是它有所不同。

 root@testbp:~# docker inspect --format '{{.State.Pid}}' ecd6395e624f 29779 root@testbp:~# nsenter -t 29779 -n ifconfig eth0 mtu 1450 root@testbp:~# docker exec -it ecd6395e624f bash root@ecd6395e624f:/bp2/src# ifconfig -a eth0 Link encap:Ethernet HWaddr 02:42:ac:10:00:33 inet addr:172.16.0.51 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fddd::33/112 Scope:Global inet6 addr: fe80::42:acff:fe10:33/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1 RX packets:641523 errors:0 dropped:0 overruns:0 frame:0 TX packets:384447 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:46196193 (46.1 MB) TX bytes:47952006 (47.9 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)