监听容器的网络请求
准备
- LightProxy -> 抓包软件
- Docker
启动
配置 docker-compose
,在 environment
配置好 http_proxy
与 https_proxy
。将 lightproxy 的证书挂载到 /usr/local/share/ca-certificates/
目录。
version: '3'
services:
myapp:
image: node:18
environment:
- https_proxy=http://host.docker.internal:12888
- http_proxy=http://host.docker.internal:12888
volumes:
- /tmp/cert:/usr/local/share/ca-certificates/
容器启动动,运行 update-ca-certificates
命令来更新证书。接下来就可以在抓包软件中看到所有的请求了。
对于 yarn 来说,如果遇到 ssl 相关的错误,可以执行 yarn config strict-ssl- false
来解决。