I have two proxies. I need to redirect all incoming traffic to the first container through the second and back. I’m a bit new to Docker and don’t understand how to do this.
Here’s an example of my compose (unnecessary parameters removed):
If necessary, I can split them into two separate containers or change the ports; that’s no problem. The main thing is that internet traffic coming to the first proxy must pass through the second one and back.
Can you share more about what the issue is? If you want socks5 proxy listening on port 1090 and forward requests to the other proxy, you would need to configure socks5 proxy to forward those requests to the hostname “mitmproxy” as that is the compose service name that works as a DNS entry as well. Is this what you were looking for?
Basically, yes. I need Socks5 to listen for incoming connections from the internet, and then redirect all incoming traffic to another proxy called mitmproxy, which will then process the traffic and return the response back to Socks5, which will then return the response to the internet.
The only problem is that I can’t configure this in Socks5 itself; I simply don’t have the necessary settings. So I need to do it using Docker. Perhaps I can somehow configure networks and do redirection? I don’t know of any way to manage this, not through a program inside the container, but through Docker itself.
Wouldn’t the client that calls the socks5 proxy tell it which target to access? So shouldn’t the client using the socks proxy internet:1090, access “mitmproxy1085” over the socks proxy itself? After all the socks proxy is a forward proxy and works in a way like an http proxy. I fail to see what docker is supposed to do here.
How would this whole flow look, if you take docker out of the equation?
No. Both of these proxies are proxies. mitmproxy is not a server, it’s also a proxy. The target object is websites. For example, if a client wants to share google.com, it should look like this:
In this case, the client has no idea that it is connected to a proxy. It accesses regular internet resources through two proxies.
The most important thing here is mitmproxy. It processes all requests passing through it. But the problem is that the client can’t connect to mitmproxy directly, so another layer is needed in the form of regular Socks5 as a simple intermediary.
In the meantime I also realized what this socks5 proxy was. I never used it, but I think I understand the problem, but not the usecase. Normally, you would set env variables like HTTP_PROXY and HTTPS_PROXY to make sure traffic in a container goes through a proxy, assuming the used tools care about the variables. Now you have two different proxies that just forwards requests to the requested destination, but I don’t know if socks5 or the specific image support any variables to route the traffic through a second proxy
When I need a proxy that forwards traffic through a specific host, I just use “socat”.
With that, you could forward the requests to the mitmproxy which then handles the rest. If your goal is really just to allow a client to access mitmproxy that it could not normally, socat could help.