The super easy way to setup a Tor SOCKS5 proxy server inside a Docker container without relay/exit feature.
-
Setup the proxy server at the first time
$ docker run -d --name tor_socks_proxy -p 127.0.0.1:9050:9050 dockerhub/tor-socks-proxy:latest
- Use
127.0.0.1
to limit the connections from localhost, do not change it unless you know you're going to expose it to a local network or to the Internet. - Change to first
9050
to any valid and free port you want, please note that port9050
/9050
may already taken if you are also running other Tor client, like TorBrowser. - Do not touch the second
9050
as it's the port inside the docker container unless you're going to change the port in Dockerfile.
If you already setup the instance before (not the first time), just start it:
$ docker start tor_socks_proxy
- Use
-
Make sure it's running, it'll take a short time to bootstrap
$ docker logs tor_socks_proxy . . . Jan 10 01:06:59.000 [notice] Bootstrapped 85%: Finishing handshake with first hop Jan 10 01:07:00.000 [notice] Bootstrapped 90%: Establishing a Tor circuit Jan 10 01:07:02.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working. Jan 10 01:07:02.000 [notice] Bootstrapped 100%: Done
-
Configure your client to use it, target on
127.0.0.1
port9050
(Or the other port you setup in step 1)Take
curl
as an example, checkout what's your IP address via Tor network:$ curl --socks5-hostname 127.0.0.1:9050 ipinfo.io/ip $ curl --socks5-hostname 127.0.0.1:9050 icanhazip.com $ curl --socks5-hostname 127.0.0.1:9050 ipecho.net/plain $ curl --socks5-hostname 127.0.0.1:9050 whatismyip.akamai.com
Take
ssh
andnc
as an example, connect to a host via Tor:$ ssh -o ProxyCommand='nc -x 127.0.0.1:9050 %h %p' target.hostname.blah
-
After using it, you can turn it off
$ docker stop tor_socks_proxy
-
Tor changes circuit automatically every 10 minutes by default, which usually bring you the new IP address, it's affected by
MaxCircuitDirtiness
config, you can override it with your owntorrc
. See the official manual for more details. -
To manually renew the IP that Tor gives you, simply restart your docker container to open a new circuit:
$ docker restart tor_socks_proxy
Just note that all the connections will be terminated and need to be reestablished.
For the Tor project sustainability, I strongly encourage you to help setup Tor bridge/exit nodes(script) and donate money to the Tor project (Not this proxy project) when you have the ability/capacity!