内部网络内部的Docker无法通过TOR代理来fetch google.com
当我将我的应用程序从互联网中隔离时,它无法通过Tor Proxy来fetch google.com, 但是,当我将其添加到Internet网络中时,它可以正常运行,并且请求确实通过Tor代理。我真的很困惑。我在做什么错?
docker-compose.yml
version: "3"
services:
tor-proxy:
image: dperson/torproxy
restart: unless-stopped
networks:
- no-internet
- internet
app:
depends_on: [tor-proxy]
build: ./
restart: unless-stopped
networks:
- no-internet
- internet # if i comment this out, fetch() will result in ETIMEDOUT
networks:
no-internet:
driver: bridge
internal: true
internet:
driver: bridge
internal: false
dockerfile
FROM node:16
WORKDIR /usr/src/app
COPY . .
CMD ["node", "index.js"]
index.js
import fetch from 'node-fetch';
import { SocksProxyAgent } from 'socks-proxy-agent';
(async () => {
const agent = new SocksProxyAgent('socks5://tor-proxy:9050');
const res = await fetch('https://google.com', { agent });
})();
When I isolate my app from the internet, it fails to fetch google.com through tor proxy,
but when I add it to the internet network, it works and the request does go through the tor proxy. I'm really confused by this. What am I doing wrong?
docker-compose.yml
version: "3"
services:
tor-proxy:
image: dperson/torproxy
restart: unless-stopped
networks:
- no-internet
- internet
app:
depends_on: [tor-proxy]
build: ./
restart: unless-stopped
networks:
- no-internet
- internet # if i comment this out, fetch() will result in ETIMEDOUT
networks:
no-internet:
driver: bridge
internal: true
internet:
driver: bridge
internal: false
Dockerfile
FROM node:16
WORKDIR /usr/src/app
COPY . .
CMD ["node", "index.js"]
index.js
import fetch from 'node-fetch';
import { SocksProxyAgent } from 'socks-proxy-agent';
(async () => {
const agent = new SocksProxyAgent('socks5://tor-proxy:9050');
const res = await fetch('https://google.com', { agent });
})();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有同样的问题不同的情况。只找到了部分卑鄙的答案,所以这是另一个,但是这不需要破坏您的iptables或我的团队。
答案:在提出请求 https:// docs时.docker.com/network
示例:curl -v -socks5-hostname tor-proxy:9050 google.com
说明:我没有一个,但是通过其他方式仍可能可以警告外部网络访问。我也很感激解释,但我们可能不会得到一个。
I have the same issue different situation. Only found partial shitty answers so here's another but this one doesn't require discombobulating your iptables or in my situation, my teams.
ANSWER: use "driver: ipvlan" on the internal network and the containers name as hostname when making requests https://docs.docker.com/network
EXAMPLE: curl -v --socks5-hostname tor-proxy:9050 google.com
EXPLANATION: I don't have one but warn external network access may still be possible by other means. i would also appreciate an explanation but we probably wont get one.
问题是DNS查找。如果您从您会跳过客户端DNS查找,该查找在一个孤立的网络中无法使用:
从评论中,如果您希望Curl使用HTTPS代理:
或者让Curl使用Socks5代理而无需进行本地DNS解决:
The problem is the DNS lookup. If you switch from socks5 to socks5h you'll skip the client side DNS lookup, which isn't available in an isolated network:
And from the comments, if you want curl to use an https proxy:
or for curl to use the socks5 proxy without doing local DNS resolution: