docker container and tor #20

Closed
opened 2024-06-17 08:03:21 +00:00 by Evhorizon · 3 comments

Hi @throwaway, I have a private docker 4get instance running locally on my own PC. I want to not expose my IP to the search engines, so I thought about setting up Tor on the host, I changed all the "false" values to "onion" in the container data/config.php, but when I try to do a search I get a "couldn't find html"error. My wild guess is that the container can't connect to tor on the host machine, is that correct? Searching through the web I found that the best solution should be tweaking the docker-compose.yaml so to run Tor in another container and haveTor and 4get in the same network. However I have no idea how to do that and the documentation about Tor in a docker container is quite sparse.
Could setting " network_mode: host" be any effective? My OS is Arch Linux.

Hi @throwaway, I have a private docker 4get instance running locally on my own PC. I want to not expose my IP to the search engines, so I thought about setting up Tor on the host, I changed all the "false" values to "onion" in the container data/config.php, but when I try to do a search I get a "couldn't find html"error. My wild guess is that the container can't connect to tor on the host machine, is that correct? Searching through the web I found that the best solution should be tweaking the docker-compose.yaml so to run Tor in another container and haveTor and 4get in the same network. However I have no idea how to do that and the documentation about Tor in a docker container is quite sparse. Could setting " network_mode: host" be any effective? My OS is Arch Linux.
Collaborator

Hello :D

I want to not expose my IP to the search engines, so I thought about setting up Tor on the host

You can use tor as socks5 proxy which should make outgoing requests go through tor
For example if you wanted to use curl with tor you'd just do

curl -x socks5://127.0.0.1:9050 <url>

My wild guess is that the container can't connect to tor on the host machine, is that correct?

Yes. Localhost inside the container would mean the container itself, not your host. You can make the host available to your 4get container by using --add-host when running your container with plain docker command. In docker compose you can use "extra_hosts" https://stackoverflow.com/a/61231167

The alternative is to run tor in another container and have them connected via networking like you mentioned. You'd need to create a Dockerfile that starts tor service on container start and a docker compose file that has both containers listed. They'd be added to the default docker network. When two containers are in the same network they are accessible via the service name (or hostname if you set that value).

https://docs.docker.com/compose/networking/
this link contains an example of how two containers can communicate in the default network created

Within the web container, your connection string to db would look like postgres://db:5432

Once you have a way to access the tor service via a hostname, you can use it as a proxy by following https://git.lolcat.ca/lolcat/4get/src/branch/master/docs/configure.md#proxies

lets say you added the host "my_tor_host" that resolved to the container running tor (or the your host running tor)
you'd create a proxy list named "my_proxy.txt" for example and mount it to /var/www/html/4get/data/proxies/

the content of "my_proxy.txt" would look like this

# format -> <protocol>:<address>:<port>:<username>:<password>
# protocol list:
# raw_ip, http, https, socks4, socks5, socks4a, socks5_hostname
socks5:my_tor_host:9050::

in docker compose you'd mount it like this

volumes:
      - ./my_proxy.txt:/var/www/html/4get/data/proxies/my_proxy.txt

Btw I haven't tried any of this. I'll try my hand at it in the near future and make an example guide :3
Hope this helps!

Hello :D >I want to not expose my IP to the search engines, so I thought about setting up Tor on the host You can use tor as socks5 proxy which should make outgoing requests go through tor For example if you wanted to use curl with tor you'd just do ``` curl -x socks5://127.0.0.1:9050 <url> ``` >My wild guess is that the container can't connect to tor on the host machine, is that correct? Yes. Localhost inside the container would mean the container itself, not your host. You can make the host available to your 4get container by using --add-host when running your container with plain docker command. In docker compose you can use "extra_hosts" https://stackoverflow.com/a/61231167 The alternative is to run tor in another container and have them connected via networking like you mentioned. You'd need to create a Dockerfile that starts tor service on container start and a docker compose file that has both containers listed. They'd be added to the default docker network. When two containers are in the same network they are accessible via the service name (or hostname if you set that value). https://docs.docker.com/compose/networking/ this link contains an example of how two containers can communicate in the default network created >Within the web container, your connection string to db would look like postgres://db:5432 Once you have a way to access the tor service via a hostname, you can use it as a proxy by following https://git.lolcat.ca/lolcat/4get/src/branch/master/docs/configure.md#proxies lets say you added the host "my_tor_host" that resolved to the container running tor (or the your host running tor) you'd create a proxy list named "my_proxy.txt" for example and mount it to /var/www/html/4get/data/proxies/ the content of "my_proxy.txt" would look like this ``` # format -> <protocol>:<address>:<port>:<username>:<password> # protocol list: # raw_ip, http, https, socks4, socks5, socks4a, socks5_hostname socks5:my_tor_host:9050:: ``` in docker compose you'd mount it like this ``` volumes: - ./my_proxy.txt:/var/www/html/4get/data/proxies/my_proxy.txt ``` Btw I haven't tried any of this. I'll try my hand at it in the near future and make an example guide :3 Hope this helps!
Author

Thanks for your quick and detailed answer:) what worked for me was the second method, I added a "tor" service based on the osminogin/tor-simple image to docker-compose.yaml, exposing the 9050 port and mounting the whole /data folder. There I changed sock5: localhost:9050:: to socks5:tor:9050:: in onion.txt and changed all the "false" values to "onion" in config.php.
However, Google scraper does always return a captcha, that's the downside of using Tor. I tried to restart the container but no joy lol. In fact, Google seems much more forgiving while searching over a VPN, at least for me.
Hoping this would be of help, thanks so much again:3

Thanks for your quick and detailed answer:) what worked for me was the second method, I added a "tor" service based on the osminogin/tor-simple image to docker-compose.yaml, exposing the 9050 port and mounting the whole /data folder. There I changed sock5: localhost:9050:: to socks5:tor:9050:: in onion.txt and changed all the "false" values to "onion" in config.php. However, Google scraper does always return a captcha, that's the downside of using Tor. I tried to restart the container but no joy lol. In fact, Google seems much more forgiving while searching over a VPN, at least for me. Hoping this would be of help, thanks so much again:3
Owner

throwie is the goat

throwie is the goat
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lolcat/4get#20
No description provided.