内部网络内部的Docker无法通过TOR代理来fetch google.com

发布于 2025-01-21 09:19:55 字数 1016 浏览 6 评论 0原文

当我将我的应用程序从互联网中隔离时,它无法通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缱绻入梦 2025-01-28 09:19:56

我有同样的问题不同的情况。只找到了部分卑鄙的答案,所以这是另一个,但是这不需要破坏您的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.

活雷疯 2025-01-28 09:19:56

问题是DNS查找。如果您从您会跳过客户端DNS查找,该查找在一个孤立的网络中无法使用:

    const agent = new SocksProxyAgent('socks5h://tor-proxy:9050');

从评论中,如果您希望Curl使用HTTPS代理:

export https_proxy=http://tor-proxy:8118/
curl https://google.com

或者让Curl使用Socks5代理而无需进行本地DNS解决:

curl --socks5-hostname tor-proxy:9050 https://google.com

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:

    const agent = new SocksProxyAgent('socks5h://tor-proxy:9050');

And from the comments, if you want curl to use an https proxy:

export https_proxy=http://tor-proxy:8118/
curl https://google.com

or for curl to use the socks5 proxy without doing local DNS resolution:

curl --socks5-hostname tor-proxy:9050 https://google.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文