Skip to content

Can't build docker image for ASP.NET Core + React #43514

Closed
@moskalenko2k24

Description

@moskalenko2k24

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am using Fedora 35, dotnet 6.0.107, Node js 16.13.1, npm 8.13.1, VS Code 1.70.2
I created new project with React using command
dotnet new react
It works

Then in VS Code I created Dockerfile(extension made it automatically).
When I ran sudo docker build . from terminal error occurs. It can't find npm.

Expected Behavior

Successful execute of docker build .

Steps To Reproduce

I created new project with React using command
dotnet new react
It works

Then in VS Code(it will be better to do it with CLI, but I didn't find how) I created Dockerfile(extension made it automatically).

FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
WORKDIR /app
EXPOSE 5166

ENV ASPNETCORE_URLS=http://+:5166

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
WORKDIR /src
COPY ["DotnetReact.csproj", "./"]
RUN dotnet restore "DotnetReact.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "DotnetReact.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DotnetReact.csproj" -c Release -o /app/publish /p:UseAppHost=false

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

Then I run
sudo docker build .

Error occurs

Step 15/19 : RUN dotnet publish "DotnetReact.csproj" -c Release -o /app/publish /p:UseAppHost=false
---> Running in 3b639c2bf685
MSBuild version 17.3.0+92e077650 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
DotnetReact -> /src/bin/Release/net6.0/DotnetReact.dll
/usr/bin/sh: 2: /tmp/tmp94ab833c60ff45ab9dd3dcb40901425e.exec.cmd: npm: not found
/src/DotnetReact.csproj(39,5): error MSB3073: The command "npm install" exited with code 127.
The command '/bin/sh -c dotnet publish "DotnetReact.csproj" -c Release -o /app/publish /p:UseAppHost=false' returned a non-zero code: 1

Exceptions (if any)

No response

.NET Version

6.0.107

Anything else?

VS Code 1.70.2
Node.js 16.13.1
npm 8.13.1

dotnet --info output
.NET SDK (reflecting any global.json):
Version: 6.0.107
Commit: f6ec7508e3

Runtime Environment:
OS Name: fedora
OS Version: 35
OS Platform: Linux
RID: fedora.35-x64
Base Path: /usr/lib64/dotnet/sdk/6.0.107/

global.json file:
Not found

Host:
Version: 6.0.7
Architecture: x64
Commit: 0ec02c8c96

.NET SDKs installed:
5.0.206 [/usr/lib64/dotnet/sdk]
6.0.107 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.9 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.7 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.9 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.7 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-spaquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions