Net Core MVC Dockeri file not working.There 没有错误我的本地项目
Net Core MVC Dockeri file not working.There is no error my local project
我在分层架构中有 net core mvc 项目 运行。它在本地工作正常但不适用于 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" ]
如您所见,该应用仅监听 localhost
。您需要设置一个环境变量来告诉 ASP.NET Core 监听所有接口,而不仅仅是主机无法访问的 localhost
。
ASPNETCORE_URLS="https://+;http://+"
您有一个 ENV ASPNETCORE_URLS="http://*:5000"
命令,但它似乎没有生效,请尝试将其指定为参数:
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
请参阅 Microsoft 文档,了解如何将 ASP.NET 核心应用程序 docker 化。
我在分层架构中有 net core mvc 项目 运行。它在本地工作正常但不适用于 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" ]
如您所见,该应用仅监听 localhost
。您需要设置一个环境变量来告诉 ASP.NET Core 监听所有接口,而不仅仅是主机无法访问的 localhost
。
ASPNETCORE_URLS="https://+;http://+"
您有一个 ENV ASPNETCORE_URLS="http://*:5000"
命令,但它似乎没有生效,请尝试将其指定为参数:
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
请参阅 Microsoft 文档,了解如何将 ASP.NET 核心应用程序 docker 化。