【问题标题】:How do I proxy every request from a dotnet core app running in a docker container如何代理来自 docker 容器中运行的 dotnet 核心应用程序的每个请求
【发布时间】:2016-12-16 22:23:24
【问题描述】:

我正在努力从在 docker 容器代理 http 请求上运行的 web api 获取我的 http 调用。我已经使用 bash 通过代理成功到达了所需的端点

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

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

现在我想在同一个容器上运行的应用程序中重新创建它

我尝试了以下方法:

  1. dotnet core proxy

        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();
    
        app.UseMvc().RunProxy(new ProxyOptions
        {
            Scheme = "http",
            Host = "example",
            Port = "7777"
        });
    
  2. 在容器创建时设置 http_proxy 环境变量

        export http_proxy=http://example:7777
    
  3. 使用 HttpClientHandler

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

谁能想到其他方法来设置代理?或有关如何调试的任何建议?

【问题讨论】:

    标签: c# docker proxy .net-core


    【解决方案1】:

    我不是 dotnet 专家,也不确定您的应用程序是如何运行的,所以我假设您像普通 nginx 一样运行您的应用程序。 我建议你像 sh -c your_app 这样运行你的应用程序,这意味着你可以将你的 docker cmd 设置为 sh -c your_app

    希望这能解决您的问题。

    顺便说一句,这个问题与kubernetes无关,你可能打错了标签;)

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 2020-03-19
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 2020-01-19
      • 1970-01-01
      相关资源
      最近更新 更多