skip to Main Content

i was containerizing my .Net + React.js application but during the process I have encountered an unexpected error. I got myself acquainted with similar posts but none of the solutions solved my problem. Since the build log is quite long I have placed in pastebin:

https://pastebin.com/PhfYW3zm

The dockerfile which I am using comes from the official documentation, and that’s why it comes to me as a surpise that it does not work:

https://learn.microsoft.com/en-us/visualstudio/containers/container-tools-react?view=vs-2022

The Dockerfile itself:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y libpng-dev libjpeg-dev curl libxi6 build-essential libgl1-mesa-glx
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
WORKDIR /src
COPY ["WebApp/WebApp.csproj", "WebApp/"]
RUN dotnet restore "WebApp/WebApp.csproj"
COPY . .
WORKDIR "/src/WebApp"
RUN dotnet build "WebApp.csproj" -c Release -o /app/build

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

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

2

Answers


  1. Chosen as BEST ANSWER

    Deleting the npm install tags from .csproj as suggested in this thread https://github.com/dotnet/sdk/issues/9593 by user PKLeso resolved the problem.

    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" /> 
    

    This will delete frontend from your container completely if I remember correctly. However if you want to remain it within container just make sure that npm install on your frontend leaves no errors. Beacuse otherwise MSB3073 error occurs.


  2. If there are dependency conflicts in the react app, for example after an upgrade of react to to the latest version, and because of that npm install invoked on the ClientApp does not run but npm install --force does run then in the .csproj add --force to the

    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    

    line, so it becomes

    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install --force" />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search