简体   繁体   English

如何拦截来自 docker 容器的 UDP 流量?

[英]How to intercept UDP traffic from a docker container?

I've got a simple application in a Docker container that listens for and transmits UDP data.我在 Docker 容器中有一个简单的应用程序,用于侦听和传输 UDP 数据。 This data is unencrypted and can be broadcasted or directed at a specific IP address.此数据未加密,可以广播或定向到特定 IP 地址。

What I would like to do is set up automated testing for this application.我想做的是为此应用程序设置自动化测试。 That is, I'd have a test script send certain packets to the application and capture / verify the response.也就是说,我有一个测试脚本向应用程序发送某些数据包并捕获/验证响应。 I'm looking for ways this packet-sniffing could be done in Docker.我正在寻找可以在 Docker 中完成这种数据包嗅探的方法。 I'd heard about mtimproxy , but it looks like it only handles HTTP/S traffic (and my application would not respect the HTTP/S_PROXY environment variable anyway).我听说过mtimproxy ,但它看起来只处理 HTTP/S 流量(而且我的应用程序无论如何都不会尊重 HTTP/S_PROXY 环境变量)。

Ideally, this packet sniffing would be done outside the container.理想情况下,此数据包嗅探将在容器外进行。 As much as possible, I'm trying to make the application's container as unaware of the testing as possible (so I would like to use --network="bridge" and expose the ports needed, just like how this container would be deployed operationally).尽可能地,我试图让应用程序的容器尽可能不知道测试(所以我想使用 --network="bridge" 并公开所需的端口,就像如何在操作上部署这个容器一样)。 The trick would be I wouldn't want any other network traffic hitting the container, just the traffic generated by the test script.诀窍是我不希望任何其他网络流量访问容器,只希望测试脚本生成的流量。 Does anyone have any ideas?有没有人有任何想法?

For anyone else with this issue, I ended up putting my test script in another docker container and using docker-compose to start them both up with a private network connecting them.对于遇到此问题的其他任何人,我最终将我的测试脚本放在另一个 docker 容器中,并使用 docker-compose 通过连接它们的专用网络启动它们。 It seems to be working well so far (I'm able to send / receive from both without an issue).到目前为止,它似乎运行良好(我可以毫无问题地从两者发送/接收)。 I'll update this answer if that changes.如果情况发生变化,我会更新此答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM