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" ]




As you can see, the app listening to
localhostonly. You need to set an environment variable to tell ASP.NET Core to listen to all interfaces, instead of justlocalhostwhich is inaccessible to host.You have a
ENV ASPNETCORE_URLS="http://*:5000"command, but it doesn't seem to take effect, try specifying it as argument:See Microsoft's docs on how to dockerize an ASP.NET Core app.