0

Something wrong with my docker desktop. Create app via template ASP.NET Core 6.0 MVC "Weather Forecast" and after run in docker my app throws exception:

 Unhandled exception. System.IO.IOException: Failed to bind to address https://[::]:443: address already in use.
     ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
     ---> System.Net.Sockets.SocketException (98): Address already in use
       at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
       at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
       at System.Net.Sockets.Socket.Bind(EndPoint localEP)
       at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint)
       at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
       --- End of inner exception stack trace ---
       at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
       at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.AnyIPListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
       at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
       at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
       at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
       at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
       at Microsoft.AspNetCore.Builder.WebApplication.Run(String url)
       at Program.<Main>$(String[] args) in D:\REPO\GptVisualRest\Test\Program.cs:line 25

How to fix it?

EDIT:

Dockerfile generated by VS 2022 - didn't edit myself:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["WebApplication1.csproj", "."]
RUN dotnet restore "./WebApplication1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]

EDIT:

enter image description here

I got error if run directly in docker via command

dotnet WebApplication1.dll
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • you are trying to bind your app to port 443, which is already in use. Either bind to another port, or free up that port by stopping whatever other app is already using it. – Claies Mar 16 '23 at 21:36
  • change port dosn't help. Got exception with another port – Евгений Mar 16 '23 at 21:39
  • well, you are using the ipv6 address `::` which is essentially loopback, it's impossible for every port to be in use. Maybe this question has your answer? https://stackoverflow.com/questions/41653805/kestrel-error-address-already-in-use-dotnet-core – Claies Mar 16 '23 at 21:43
  • Does this answer your question? [Kestrel error: address already in use (dotnet core)](https://stackoverflow.com/questions/41653805/kestrel-error-address-already-in-use-dotnet-core) – Claies Mar 16 '23 at 21:44
  • Can you edit your post and add your Dockerfile and show how you run it, please? – Hans Kilian Mar 16 '23 at 21:46
  • Your Dockerfile doesn't set ASPNETCORE_URLS, so as shown, the container should only listen on port 80. For some reason it listens on port 443 and you need to show us why it does that. It's probably some VS setting if you run the container from VS. – Hans Kilian Mar 16 '23 at 21:58
  • @HansKilian edit post to show urls – Евгений Mar 16 '23 at 22:10
  • i think trouble with Kestrel. No port used. Just Kestrel cant bind secure socket with ssl – Евгений Mar 16 '23 at 22:13

0 Answers0