我还没有找到一种npm install在构建过程中做适当的事情来构建ASP.NET Core 2.1 Docker映像的方法。
npm install
我Dockerfile看起来像这样(从Visual Studio生成的):
Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 FROM microsoft/dotnet:2.1-sdk AS build WORKDIR /src COPY --from=frontend . . COPY ["myProject.WebUi/myProject.WebUi.csproj", "myProject.WebUi/"] COPY ["myProject.SearchIndex/myProject.SearchIndex.csproj", "myProject.SearchIndex/"] COPY ["myProject.SearchIndex.Common/myProject.SearchIndex.Common.csproj", "myProject.SearchIndex.Common/"] RUN dotnet restore "myProject.WebUi/myProject.WebUi.csproj" COPY . . WORKDIR "/src/myProject.WebUi" RUN dotnet build "myProject.WebUi.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "myProject.WebUi.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "myProject.WebUi.dll"]
在以前的Microsoft映像中(例如aspnetcore-build:2.0),提供了第三方工具,例如npm,yarn,bower,pip等。
目前,我npm install在项目文件夹中执行本地操作。但是,对于像Docker Hub或Azure Container Registry提供的自动构建功能,缺少注释模块。
找到了解决方案:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 FROM microsoft/dotnet:2.1-sdk AS build WORKDIR /src COPY --from=frontend . . COPY ["myProject.WebUi/myProject.WebUi.csproj", "myProject.WebUi/"] COPY ["myProject.SearchIndex/myProject.SearchIndex.csproj", "myProject.SearchIndex/"] COPY ["myProject.SearchIndex.Common/myProject.SearchIndex.Common.csproj", "myProject.SearchIndex.Common/"] RUN dotnet restore "myProject.WebUi/myProject.WebUi.csproj" COPY . . WORKDIR "/src/myProject.WebUi" RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -yq nodejs build-essential RUN npm install -g npm RUN npm install RUN dotnet build "myProject.WebUi.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "myProject.WebUi.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "myProject.WebUi.dll"]