Skip to content

Instantly share code, notes, and snippets.

@robinvanderknaap
Created January 5, 2023 13:30
Show Gist options
  • Save robinvanderknaap/ae0e0385d18b2fd983c928c920886a66 to your computer and use it in GitHub Desktop.
Save robinvanderknaap/ae0e0385d18b2fd983c928c920886a66 to your computer and use it in GitHub Desktop.
Using NodeJS and NPM in Dockerfile in dotnet container
FROM mcr.microsoft.com/dotnet/sdk:6.0.401 AS build-env
WORKDIR /app
# https://jordananderson.io/asp-react-nodejs-docker/
ENV NODE_VERSION 16.17.1
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 \
&& tar -xzf "nodejs.tar.gz" -C /usr/local --strip-components=1 \
&& rm nodejs.tar.gz \
&& apt update \
&& apt-get install -y nodejs
# Copy csproj and restore as distinct layers
COPY src/SomeProject/*.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY src/SomeProject ./
RUN rm -rf node_modules
RUN npm install
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0.9
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "SomeProject.dll"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment