runtime: http request in docker container fails with curl error
Near the end of converting a webapi 2 service to aspcore I’ve run up against a problem hosting the aspcore service in docker. The problem is that no HttpRequest are working anymore in the project. They throw the follow exception:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: Couldn't connect to server
at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
And they only throw this exception when running inside the docker container FROM microsoft/dotnet:1.0-runtime
and FROM microsoft/dotnet:1.1.1-runtime
This exception doesn’t occur on the host machine running docker and has been no problem so far as I rebuild the project piece by in a new solution. I believe this issue might have started after migrating to csproj from project.json.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 33 (16 by maintainers)
I’m facing same issue. Does anyone have solution?
Hi guys,
I can confirm this is a proxy-related issue. Thanks for all the help!
Running into the same problem, curl from within the container works but not HttpClient which produces
The port 80 shouldn’t matter but posting to both
http://api
andhttp://api:80
didn’t work. The exposed port 3002 is intended for external access not for inter-container communications.