docker - Docker 在构建期间记录网络流量
问题描述
在 docker 中,如何记录构建期间发生的所有网络流量。
我想我会修改我的 dockerfile 来监控和收集所有网络请求。例如从apt-get install
和安装 node 或 rubygem 包
我可以修改 Dockerfile 以收集日志或以其他方式输出它。
关于我如何做到这一点的任何建议?
解决方案
所有网络流量 = 所有接口(loopback
包括)和所有协议上的流量(不仅http/https
,您可以通过代理使用日志记录)。在所有接口的每个命令开始tcpdump
时在后台启动 ( )。示例,它将所有数据包打印到:RUN
eth0, lo
stdout
FROM alpine
RUN apk add tcpdump
# start tcpdumps in the background for each RUN
RUN sh -c 'tcpdump -nnXSs 0 -i eth0 &' \
&& sh -c 'tcpdump -nnXSs 0 -i lo &' \
&& ping -c 5 google.com
RUN sh -c 'tcpdump -nnXSs 0 -i eth0 &' \
&& sh -c 'tcpdump -nnXSs 0 -i lo &' \
&& apk add curl
构建输出:
...
Step 3/4 : RUN sh -c 'tcpdump -nnXSs 0 -i eth0 &' && sh -c 'tcpdump -nnXSs 0 -i lo &' && ping -c 5 google.com
---> Running in 63249712af4a
PING google.com (216.58.204.78): 56 data bytes
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
64 bytes from 216.58.204.78: seq=0 ttl=127 time=17.529 ms
13:01:09.987047 IP 8.8.4.4.53 > 172.17.0.2.43264: 41194 1/0/0 A 216.58.204.46 (44)
0x0000: 4500 0048 7096 0000 7f11 12f0 0808 0404 E..Hp...........
0x0010: ac11 0002 0035 a900 0034 0472 a0ea 8180 .....5...4.r....
0x0020: 0001 0001 0000 0000 0667 6f6f 676c 6503 .........google.
0x0030: 636f 6d00 0001 0001 c00c 0001 0001 0000 com.............
0x0040: 001e 0004 d83a cc2e
...
当然,您可以将这些日志发送到 Elasticsearch/Splunk/...,但您需要安装更多工具。并且可能最好将这些流量排除在tcpdump
.
推荐阅读
- c# - 方法重载返回类型
- r - 如何按 R 中预先确定的因子级别顺序对数据框进行排序?
- javascript - 如何使用 URLSearchParams 从给定 url 中的一组值中有效地仅删除一个查询字符串?
- javascript - 下面的代码有什么用。它应该做什么
- css - 消除两个引导列之间的空间
- android - MediaPlayer 在 Activity.recreate() 之后继续播放
- ios - 再现键中的比例必须与图像描述中传入的比例相匹配
- r - 网页抓取多个页面
- azure - Bot Framework:如何配置 OAuth 连接以使用虚拟助手中的附加技能
- swift - 点击特定行时如何从 Firestore 获取特定信息