I’m stuck on the problems.
I know It maybe is a bad question, but
I can’t do anything.
I have some code test like that:
[HttpGet]
public async Task<object> Get()
{
try
{
Console.WriteLine("Start");
HttpClient httpClient = new HttpClient()
{
BaseAddress = new Uri("https://pikbest.com")
};
Console.WriteLine("Start call");
var response = await httpClient.GetStringAsync("?m=download&id=123&flag=1&free_zone=0");
Console.WriteLine("Call ok");
} catch(Exception ex)
{
Console.WriteLine($"Exception: {ex.InnerException}\n{ex.Message}\n{ex.StackTrace}");
return "Not ok";
}
return "Ok";
}
When I ran with Docker
only, It’s return Ok
.
But when I ran with Docker-compose
, It’s return Not ok
.
Dockerfile
:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
WORKDIR /app
COPY . ./
RUN dotnet restore
RUN dotnet publish -c Release -o ./publish
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build /app/publish .
EXPOSE 80/tcp
ENTRYPOINT ["dotnet", "testhttpclient.dll"]
And here is docker-compose.yml
:
version: "3"
services:
serverside:
build: ./testhttpclient
container_name: testhttpclient
ports:
- '80:80'
This is Console.Write logs:
testhttpclient | Start
testhttpclient | Start call
testhttpclient | Exception: System.Net.Sockets.SocketException (11): Resource temporarily unavailable
testhttpclient | at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
testhttpclient | Resource temporarily unavailable
testhttpclient | at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
testhttpclient | at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
testhttpclient | at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask)
testhttpclient | at testhttpclient.Controllers.WeatherForecastController.Get() in /app/Controllers/WeatherForecastController.cs:line 40
tController.Get( ) in /app/Controllers/WeatherForecastController.cs:line 40
My VPS Centos info:
Icon name: computer-vm
Chassis: vm
Machine ID: e3897617bcc74a32826c8ab5936dd768
Boot ID: bf2e723b743f456a834414dbe372177b
Virtualization: kvm
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-147.5.1.el8_1.x86_64
Architecture: x86-64
Really thank you!