该项目不知道如何运行配置文件docker

时间:2019-05-17 10:32:52

标签: .net docker .net-core dockerfile visual-studio-2019

我使用dockerfile从git中拉出一个项目,我能够通过命令行构建映像,但是Visual Studio说“我不知道该项目如何运行配置文件docker”,我正在使用vs2019。有什么建议吗?

我已经检查了此https://stackoverflow.com/a/54485107/1219916,但没有解决我的问题

这是我的dockerfile

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1803 AS base WORKDIR /app EXPOSE 80 EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1803 AS build WORKDIR /src COPY ["WebApi/WebApi.csproj", "WebApi/"] RUN dotnet restore "WebApi/WebApi.csproj" COPY . . WORKDIR "/src/WebApi" RUN dotnet build "WebApi.csproj" -c Release -o /app

FROM build AS publish RUN dotnet publish "WebApi.csproj" -c Release -o /app

FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "WebApi.dll"]

1 个答案:

答案 0 :(得分:0)

您必须单独获得dotnet核心SDK和运行时,而不是与nanoserver一起获得。 它将解决您的问题。

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base WORKDIR /app EXPOSE 80 EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY ["WebApi/WebApi.csproj", "WebApi/"] RUN dotnet restore "WebApi/WebApi.csproj" COPY . . WORKDIR "/src/WebApi" RUN dotnet build "WebApi.csproj" -c Release -o /app

FROM build AS publish RUN dotnet publish "WebApi.csproj" -c Release -o /app

FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "WebApi.dll"]