Issue
I'm trying to create basic Dockerfile for.NET 7 project which I created using dotnet new angular
.
Build process is running on AWS CodeBuild but whatever I try, I get npm: not found
or something similar.
Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
build-essential \
nodejs
WORKDIR /src
COPY net7_test.csproj ./
RUN dotnet restore "./net7_test.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "net7_test.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "net7_test.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "net7_test.dll"]
What am I missing? The structure of directory is default scaffolded project so Dockerfile and .csproj are on the same level.
EDIT:
It works using this lines instead of apt:
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -yq nodejs build-essential
But it says that the script is deprecated. So what is correct way of installing node and npm?
Solution
Your Dockerfile installs Node's oldest version, and that bundle doesn't contain npm. All instructions on how to install Node for Debian are available on NodeSource.
Try this:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
ARG NODE_MAJOR
RUN apt-get update && \
apt-get install -y ca-certificates curl gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && \
apt-get install nodejs -y
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["tail", "-f", "/dev/null"]
Answered By - Jacobs Monarch Answer Checked By - Marilyn (WPSolving Volunteer)