I have not found a way to build a ASP.NET Core 2.1 Docker image while doing a proper npm install
during the build process.
My Dockerfile
looks like this (one that has been generated from 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"]
In the previous images from Microsoft (e.g. aspnetcore-build:2.0) were third-party tools provided, such as npm, yarn, bower, pip, ...)
At the moment I do a local npm install
in the project folder. But for automatic building like it is offered from Docker Hub or Azure Container Registry the note modules are missing.
RUN npm install
afterWORKDIR "/src/myProject.WebUi"
. In case there is nonpm
in the base image, then also addRUN apt-get update && apt-get install -y nodejs
before it. – qbikapt-get install npm
is not available. – dannyyy