我正在努力从在 Docker 容器代理 http 请求上运行的 Web API 获取我的 http 调用。我已经使用 bash 通过代理成功到达了所需的端点
docker exec -i -t 665b4a1e17b6 /bin/bash
和
http_proxy=http://exampleProxy:7777 curl -s http://endpoint
现在我想在同一容器上运行的应用程序中重新创建它
我尝试了以下方法:
-
loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseMvc().RunProxy(new ProxyOptions { Scheme = "http", Host = "example", Port = "7777" });
在创建容器时设置 http_proxy 环境变量
export http_proxy=http://example:7777
使用 HttpClientHandler
var handler = new HttpClientHandler { Proxy = new WebProxy("http://example:777) }; var client = new HttpClient(handler); etc....
有没有人能想到其他设置代理的方法?或者关于如何调试这个的任何建议?
最佳答案
我不是 dotnet 专家,也不确定你的应用程序是如何运行的,所以我假设你的应用程序像普通的 nginx 一样运行。
我建议您像这样运行您的应用程序 sh -c your_app
,这意味着您可以将 docker cmd 设置为 sh -c your_app
。
希望这能解决您的问题。
顺便说一句,这个问题与 kubernetes 无关,你可能有错误的标签;)
关于c# - 如何代理来自在 docker 容器中运行的 dotnet 核心应用程序的每个请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41193283/