Docker container: connect to tor network through proxy #42
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello @throwaway! I configured 4get locally (just on my laptop) using docker container with tor and now I want to configure tor to use Socks5Proxy from torrc (because some ISPs block tor in my country, so I use shadowsocks proxy on 127.0.0.1:1080), but for some reason it does not read this line (returns to default torrc config with just SocksPort 0.0.0.0:9050 and nothing else?), as I can tell after some tests. My local tor daemon which runs out of docker container works fine with this proxy though. Can you help me?
As I understand it, tor container uses its own local tor daemon, so it can't use "global proxy" which runs on localhost (or how to call it idk). So what's the solution here? Maybe somehow run local shadowsocks proxy inside this container so this local tor daemon can actually see it? If so, how to do that? Or maybe if I'm already running "global" tor daemon on my machine, then somehow configure container to use it? I tried to do this but no luck.
Hello! :D
From my understanding, you are running shadowsocks on your host machine and want traffic to flow from 4get, to shadowsocks, and then to tor. And you tried to accomplish this by providing the options
Socks5Proxy
,Socks5ProxyUsername
, andSocks5ProxyPassword
options to the torrc (at /etc/tor/torrc) which point to your running shadowsocks instance at 127.0.0.1:1080if you're running tor on your local machine, the easiest way is to remove the tor container in your compose file and make 4get container use host networking. Then in
proxies/onion.txt
you can usesocks5:localhost:9050::
you can make 4get container use host network with
network_mode: "host"
with onion.txt in
proxies
folder, your compose file would look like this:if you're adamant about running tor in a docker container, it becomes much trickier as you have experience. The torrc at /etc/tor/torrc only applies to tor running on your host, not the container running tor, and 127.0.0.1:1080 in the container means the container itself and not your host running shadowsocks
to make shadowsocks on your host machine visible to the tor container, you could add your host machine with
extra_hosts
in docker compose. Then your tor container (with an updated torrc which will be covered next) can reference your host and it can use it as a Socks5Proxy.using
extra_hosts foorbar:127.0.0.1
will not work because it will simply append the value of 127.0.0.1 to /etc/hosts in the containerthere is a special string
host-gateway
that allows you to reference the host machine. You can use it like thisThis adds your host machine to /etc/hosts in the container and makes it available via an ip address such as
172.17.0.1
but as https://stackoverflow.com/a/70725882 elaborates, in docker compose you'll likely end up with an ip that you can't predict ahead of time unless you create a custom network.
The added section to your docker compose file will look like this:
which will allow this container to communicate with your host machine via the ip "172.17.0.1" or some other ip
to make changes to the tor daemon running in the container, you need to modify the configuration it reads from. To do this, you can mount an updated version of the configuration. For example: you can create a torrc named
my_torrc
with the following content and mount it with docker compose to the expected location of/etc/tor/torrc
Everything else regarding the connection between 4get and tor should remain the same as what is in the docker_tor guide. I'll need to look into using custom network like https://stackoverflow.com/a/70725882 mentions so the ip referencing host can be consistent.
Hopefully this helps! I've also written more about docker networking here #20 (comment) but I know now using 127.0.0.1 with extra_hosts will not work
@throwaway Ok, so I ended up with the easiest way, because I'm always running tor on my machine, and it works! Now I only worry about one thing: is it safe to use
SOCKSPort 0.0.0.0:9050
line in /etc/tor/torrc ? I don't quite understand this part from the guide:I want to be safe, so I don't want it to be accesible to outside world. So how to make sure that I don't publish this port? Does this
--publish
flag relate to tor daemon or something else (I didn't find anything about this flag inman tor
)? I didn't open this port on my firewall, so am I safe in this case?Edit: Now when I'm using
network_mode: "host"
line in compose file and restart container, it saysSo does it mean that it automatically protects from publishing port to outside world (and I'm safe)?
Glad it know it works!
the reason why SocksPort is set to
0.0.0.0:9050
instead of the default of 127.0.0.1 is because the docker_tor guide was made for a setup that involved both containers and was needed so the tor and 4get containers could communicate with each other on the same network. Because you're removing the need the tor container, you don't need this line in your tor conf!No. With
network_mode: host
all ports are automatically published, so if a process in a container is listening on port 8080 then you can access it at port 8080 on the host.The message is shown to inform you that this section is ignored
Going to edit my previous comment to remove the SocksPort line. Thank you for pointing this out!
@throwaway thank you so much <3 Finally I can use my local 4get instance without reserve!