如何为单个Docker容器捕获数据包

sop*_*ope 9 networking docker

主机上运行着许多容器。我想捕获其中一个容器的数据包。有什么办法吗?

小智 23


Eti*_*ier 18

来自和用于带有 Wireshark 的工作站:

docker exec -ti <container id> cat /sys/class/net/eth0/iflink

28
Run Code Online (Sandbox Code Playgroud)
ip link | grep 28

28: veth11b0a6c@if27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default
Run Code Online (Sandbox Code Playgroud)

Wireshark 接口


BMi*_*tch 6

您可以将一个容器的网络名称空间绑定到另一个:

docker run -it --rm --net container:<container_name> \
  nicolaka/netshoot tcpdump ...
Run Code Online (Sandbox Code Playgroud)

要查看有关上面使用的netshoot图像的更多信息,请参见:https : //github.com/nicolaka/netshoot