Je n'ai pas trouvé de moyen de construire une image Docker ASP.NET Core 2.1 tout en faisant un npm install
Correct pendant le processus de construction.
Mon Dockerfile
ressemble à ceci (celui qui a été généré à partir de Visual Studio):
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"]
Dans les images précédentes de Microsoft (par exemple aspnetcore-build: 2.0), des outils tiers étaient fournis, tels que npm, yarn, bower, pip, ...)
En ce moment, je fais un npm install
Local dans le dossier du projet. Mais pour la construction automatique telle qu'elle est proposée à partir de Docker Hub ou Azure Container Registry, les modules de note sont manquants.
Trouvé la solution:
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"]