Net Core MVC Dockeri file not working.There is no error my local project

279 Views Asked by At

I have net core mvc project running in layered architecture. It works fine locally but not with docker

FROM mcr.microsoft.com/dotnet/sdk:5.0 as build
WORKDIR /app
COPY ./MyBlog.Shared/MyBlog.Shared.csproj ./MyBlog.Shared/
COPY ./MyBlog.Data/MyBlog.Data.csproj ./MyBlog.Data/
COPY ./MyBlog.Services/MyBlog.Services.csproj ./MyBlog.Services/
COPY ./MyBlog.Entities/MyBlog.Entities.csproj ./MyBlog.Entities/
COPY ./MyBlog.Mvc/MyBlog.Mvc.csproj ./MyBlog.Mvc/
COPY MyBlog.sln .
RUN dotnet restore
COPY . .
RUN dotnet publish ./MyBlog.Mvc/MyBlog.Mvc.csproj -o /publish/
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /publish .
ENV ASPNETCORE_URLS="http://*:5000"
ENTRYPOINT ["dotnet","MyBlog.Mvc.dll" ]

Layers Image

Dockerfile debug Image

Dockerfile output Image

Error Image

1

There are 1 best solutions below

1
abdusco On BEST ANSWER

As you can see, the app listening to localhost only. You need to set an environment variable to tell ASP.NET Core to listen to all interfaces, instead of just localhost which is inaccessible to host.

ASPNETCORE_URLS="https://+;http://+"

You have a ENV ASPNETCORE_URLS="http://*:5000" command, but it doesn't seem to take effect, try specifying it as argument:

docker run 
  --rm -it 
  -p 8000:80 
  -p 8001:443 
  -e ASPNETCORE_URLS="https://+;http://+" 
  -e ASPNETCORE_HTTPS_PORT=8001 
  -e ASPNETCORE_Kestrel__Certificates__Default__Password="password" 
  -e ASPNETCORE_Kestrel__Certificates__Default__Path=\https\aspnetapp.pfx 
  -v %USERPROFILE%\.aspnet\https:C:\https\ 
  mcr.microsoft.com/dotnet/core/samples:aspnetapp

See Microsoft's docs on how to dockerize an ASP.NET Core app.