Cant access .Net Core app via Docker on Windows (localhost)

I created a docker file and exposed the port. I also setup my program.cs to read those URLs + ports yet I can't access it.

From what I can see in the docker console is that my app is running. I just cant reach it.

I have tried localhost:5024 and 172.17.0.2:5024 but it just doesn't hit it.

enter image description here

Here is my docker file

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build

WORKDIR /app

EXPOSE 80
EXPOSE 5024

# copy csproj and restore as distinct layers
COPY *.sln .
COPY Api/*.csproj ./Api/

RUN dotnet restore

# copy everything else and build app
COPY Api/. ./Api/
COPY Api.Core/. ./Api.Core/

WORKDIR /app/Api
RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /app

COPY --from=build /app/Api/out ./
ENTRYPOINT ["dotnet", "Api.dll"]

This is my program.cs

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
                webBuilder.UseIISIntegration();
                webBuilder.UseKestrel();
                webBuilder.UseStartup<Startup>();
                webBuilder.UseUrls("http://*:5024");
            });

And I run these commands to get it running

docker build -f Api/Dockerfile -t quiplogs_api .
docker run -d -p 5024:80 --name app quiplogs_api


Read more here: https://stackoverflow.com/questions/64953816/cant-access-net-core-app-via-docker-on-windows-localhost

Content Attribution

This content was originally published by JcMey3r at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: