Configuring Dockerfile for an ASP.NET Core 2.1 Ang

2020-02-26 09:40发布

I'm a complete newbie on Docker and currently trying to create an ASP.NET Core 2.1 with Angular project. I'm using a Linux Container on Docker for Windows and my IDE is VS2017 community edition.

Currently, I'm receiving this error:

[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.

I believe I need to install Node.js in my Docker instance or whatever you call that, and it should be through Dockerfile. Please point out my mistakes in my assumption. And how to ensure that the dependencies will be installed regardless on what kind of container I'm using? I'm expecting that my future projects will be installed on different platforms.

4条回答
冷血范
2楼-- · 2020-02-26 10:04

This is the similar solution to the existing problem. Please followed the below link AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:

查看更多
爷、活的狠高调
3楼-- · 2020-02-26 10:04

Because of publish happens on based microsoft/dotnet:2.1-sdk image. So, this base image contains only dotnet sdk but not npm installed this base image. There are 2 steps for solving this problem:

1) Adding installation nodejs to existing dotnet:2.1-sdk as written in answer by @Marcel.

or

2) You may add additional step to Dockerfile for building frontend side based on NODE image and build your Angular. After success build you will get generated frontend files and will copy them to runtime image on final stage. So you will not add any installation to dotnet sdk with this option and with one Dockerfile with multiple stages you will build backend side seperately and frontend site seperately.

If you would like to make it as second option, please follow below link for building frontend on Dockerfile seperately with ASP.NET Core on same docker file:

Dockerize ASP.NET Core Angular application (Solving error: The command “npm install” exited with code 127.)

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-02-26 10:10

Instead of install NPM and Node.js to the base image, you can also choose a base image that has the frameworks preinstalled. You can use my dotnet-angular image which is publicly available on hub.docker.com. Just replace

FROM microsoft/dotnet:2.2-sdk AS build

with

FROM mjibrandl/dotnetcore-angular:latest AS build

Check also my article: Setup Azure DevOps YAML pipeline to publish a .NET Core Angular 7 docker container to Azure Container Registry

查看更多
我命由我不由天
5楼-- · 2020-02-26 10:20

In the microsoft/dotnet:2.1-aspnetcore-runtime container image npm/nodejs is not installed. To install this in the container update the docker file

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base

# Setup NodeJs
RUN apt-get update && \
    apt-get install -y wget && \
    apt-get install -y gnupg2 && \
    wget -qO- https://deb.nodesource.com/setup_6.x | bash - && \
    apt-get install -y build-essential nodejs
# End setup

WORKDIR /app
EXPOSE 80

Only Angular CLI live reload is not working.

查看更多
登录 后发表回答