1

I have a docker-compose file which runs a tor node and I also have a simple Go script which attempts to use torgo to connect to said tor node.

I run the docker-compose and then I run a simple curl command to check that the SOCKS5 proxy is working, all is fine:

$ curl --socks5 127.0.0.1:9050 https://check.torproject.org/api/ip
{"IsTor":true,"IP":"185.83.214.69"}

But if I run my Go script to try and connect with port 9051 to get a controller instance, every attempt fails with error EOF.

I've also tried connecting via telnet and receive errors there as well:

$ telnet 127.0.0.1 9051
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

I've tried a number of different things at this point, too many to recall right now but things including, different docker images, mounting my own torrc config with auth enabled and various other parameters, etc. Nothing is working...

What am I missing? How can I connect to the ControlPort?

docker-compose

version: "3.8"

services:
  torproxy:
    restart: always
    image: dperson/torproxy:latest
    ports:
      - "9050:9050" # Tor proxy
      - "9051:9051" # Tor control port
      - "8118:8118" # Privoxy

main.go

package main

import (
    "github.com/wybiral/torgo"
    "log"
)

func main() {
    addr := "127.0.0.1:9051"
    c, err := torgo.NewController(addr)
    if err != nil {
        log.Fatalf("failed to create tor controller: %s", err)
    }
    log.Println(c)
}
DjH
  • 1,448
  • 2
  • 22
  • 41
  • It takes time for the node to connect and setup its network routes. It might just be you need to implement a retry strategy to give it the required time before giving it up. https://github.com/dperson/torproxy#exposing-the-port –  Oct 10 '21 at 08:32

1 Answers1

1

I was finally able to connect to the Docker tor instance by binding the ControlPort to 0.0.0.0:9051 in torrc, rather than the default.

torrc default

ControlPort 9051

torrc updated

ControlPort 0.0.0.0:9051

This makes the control port accessible from outside the container.

This SO post got me to this answer: https://stackoverflow.com/a/58138489/5750392

DjH
  • 1,448
  • 2
  • 22
  • 41