chad
chad

Reputation: 564

Docker ASP.NET Core Container is Not Responding on the Configured Port

I am attempting to containerize an ASP.Net Core app but I am encountering issues getting the container to respond to requests on the configured and mapped port.

The app functions as expected when running locally in IIS or IISExpress.

The image builds and the container runs. Everything appears to be functional yet requests to http://localhost:49274 always result in no response/timeout.

This Dockerfile is based on the Microsoft ASP.Net Core Docker sample app - https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile. The sample app image runs without incident.

What am I doing wrong?

Dockerfile

FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY src/Auth.Provider/*.csproj ./src/Auth.Provider/
RUN dotnet restore "src/Auth.Provider/Auth.Provider.csproj" 

# copy everything else and build app
COPY src/Auth.Provider/. ./src/Auth.Provider/
WORKDIR /app/src/Auth.Provider
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS runtime
WORKDIR /app
COPY --from=build /app/src/Auth.Provider/out ./
ENTRYPOINT ["dotnet", "Auth.Provider.dll"]

I also tried adding the following commands to the Dockerfile:

EXPOSE 49274/tcp
ENV ASPNETCORE_URLS http://*:49274

docker container run command:

docker run -it -p 49274:49274 --name auth.provider auth.provider:1.0 cmd

Attempts to test the port also fail:

Test-NetConnection -ComputerName "localhost" -Port 8080

App initialization:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  WebHost.CreateDefaultBuilder(args)
    .ConfigureLogging((hostingContext, logging) =>
    {
      logging.ClearProviders();
      logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

      if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != EnvironmentName.Development)
      {
        return;
      }

      logging.AddDebug();
      logging.AddConsole();
    })
    .UseNLog()
    .UseKestrel()
    .UseUrls("http://localhost:49274")
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseStartup<Startup>();

}

Upvotes: 1

Views: 1997

Answers (1)

chad
chad

Reputation: 564

Changing localhost to * for the UseUrls method call did the trick.

.UseUrls("http://localhost:49274")

.UseUrls("http://*:49274")

Upvotes: 2

Related Questions