How can I proxy every request from the main dotnet application running in the docker container

I'm struggling to get my http calls from a web api running on docker HTTP proxies. I successfully reached the desired endpoint through a proxy using bash

docker exec -i -t 665b4a1e17b6 /bin/bash 

and

http_proxy=http://exampleProxy:7777 curl -s http://endpoint

Now I want to recreate this from an application running in the same container

I tried the following:

  • dotnet proxy

        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();
    
        app.UseMvc().RunProxy(new ProxyOptions
        {
            Scheme = "http",
            Host = "example",
            Port = "7777"
        });
    
  • Setting the http_proxy environment variable when creating the container

        export http_proxy=http://example:7777
    
  • Using HttpClientHandler

    var handler = new HttpClientHandler
    {
        Proxy = new WebProxy("http://example:777)
    };
    var client = new HttpClient(handler);
    etc....
    

Can anyone think of other ways to create a proxy server? or any recommendations on how to debug this?

+4
source share
1 answer

dotnet , , , , nginx. , , sh -c your_app, , docker cmd sh -c your_app.

, .

, , ;)

0

Source: https://habr.com/ru/post/1664012/


All Articles