Recently I've created an aspnetcore-2.2 project from a react template, which, as i noticed, doesn't have docker support out of the box.
So I added dockerfile which was generated by VS'17:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
COPY ["SpaProj.WebUI/SpaProj.WebUI.csproj", "SpaProj.WebUI/"]
COPY ["SpaProj.Application/SpaProj.Application.csproj", "SpaProj.Application/"]
COPY ["SpaProj.Domain/SpaProj.Domain.csproj", "SpaProj.Domain/"]
COPY ["SpaProj.Persistence/SpaProj.Persistence.csproj", "SpaProj.Persistence/"]
RUN dotnet restore "SpaProj.WebUI/SpaProj.WebUI.csproj"
COPY . .
WORKDIR "/src/SpaProj.WebUI"
RUN dotnet build "SpaProj.WebUI.csproj" -c Release -o
FROM build AS publish
RUN dotnet publish "SpaProj.WebUI.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SpaProj.WebUI.dll"]
As far as my research goes, the latest dotnet
images don't have nodejs pre-installed so the outcome was a foregone conclusion:
System.AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.
[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Make sure the executable is in one of those directories, or update your PATH.
[2] See the InnerException for further details of the cause.)) ---> System.AggregateException: One or more errors occurred. (Failed to start 'npm'. To resolve this:.
And so on.
After that, I was browsing web for like two complete days to resolve the issue, and after some research added few lines (which, as i thought, would help me to install/launch nodejs) into my dockerfile:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS Base
WORKDIR /app
EXPOSE 80 443
FROM microsoft/dotnet:2.2-sdk AS build
# install node and npm
ENV NODE_VERSION 10.16.0
ENV NODE_DOWNLOAD_SHA 2e2cddf805112bd0b5769290bf2d1bc4bdd55ee44327e826fa94c459835a9d9a
ENV NODE_DOWNLOAD_URL https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz
RUN wget "$NODE_DOWNLOAD_URL" -O nodejs.tar.gz \
&& echo "$NODE_DOWNLOAD_SHA nodejs.tar.gz" | sha256sum -c - \
&& tar -xzf "nodejs.tar.gz" -C /usr/local --strip-components=1 \
&& rm nodejs.tar.gz \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
# install npm packages first, this is slow so we want to minimise the number of un-cached runs
WORKDIR /src/SpaProj.WebUI/ClientApp/
COPY SpaProj.WebUI/ClientApp/package.json .
COPY SpaProj.WebUI/ClientApp/package-lock.json .
RUN npm install
RUN npm audit fix
# restore dotnet before build to allow it sit to cache
WORKDIR /
COPY ["SpaProj.Application/SpaProj.Application.csproj", "src/SpaProj.Application/"]
COPY ["SpaProj.Domain/SpaProj.Domain.csproj", "src/SpaProj.Domain/"]
COPY ["SpaProj.Persistence/SpaProj.Persistence.csproj", "src/SpaProj.Persistence/"]
COPY ["SpaProj.WebUI/SpaProj.WebUI.csproj", "src/SpaProj.WebUI/"]
RUN dotnet restore src/SpaProj.WebUI/SpaProj.WebUI.csproj
# copy source files and build
COPY . /src
RUN dotnet build /src/SpaProj.WebUI/SpaProj.WebUI.csproj --no-restore -c Release
RUN dotnet publish /src/SpaProj.WebUI/SpaProj.WebUI.csproj --no-restore -c Release -o /app
# Copy compiled app to runtime container
FROM base AS final
COPY --from=build /app .
CMD ["dotnet", "SpaProj.WebUI.dll"]
But it didnt help at all. I also tried multistage build to gather dependencies from node image like this:
FROM 10.16.1-jessie as node-build
WORKDIR /src
COPY SpaProj.WebUI/ClientApp .
RUN npm install
RUN npm run build
The app was still throwing the same exception.
Did anyone had the same issue? Is there another was to dockerize this kind of app?