angular - 为 Angular 项目启用 Docker 支持

标签 angular docker asp.net-core visual-studio-2017

Visual Studio 2017 中是否有办法自动启用对 asp.net-core Angular 项目的 Docker 支持?创建新选项时该选项被禁用。它仅适用于Web 应用程序 (MVC)

在创建项目后,我能够为 Angular 项目启用 Docker 支持(项目->添加->Docker 支持),但是当我启动应用程序时,我收到一个异常,即 node.js 不可用。

System.AggregateException occurred HResult=0x80131500 Message=One or more errors occurred. (Failed to start Node process. To resolve this:.

[1] Ensure that Node.js 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 Node executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause.)
Source= StackTrace: at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options) at WebApplication3.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in C:\Users\temp\Documents\Visual Studio 2017\Projects\WebApplication3\Startup.cs:line 34

Inner Exception 1: InvalidOperationException: Failed to start Node process. To resolve this:.

[1] Ensure that Node.js 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 Node executable is in one of those directories, or update your PATH.

[2] See the InnerException for further details of the cause.

Inner Exception 2: Win32Exception: No such file or directory

如果无法自动创建它,如何手动为我的 Angular 项目启用 Docker 支持?

最佳答案

我解决了我的问题。

我还需要在我的镜像上安装nodejs,因为webpack需要它。我已更改 Dockerfile 以安装 Nodejs 版本 6

FROM microsoft/aspnetcore:2.0
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
# Rest of Dockerfile

仅使用RUN apt-get update && apt-get install -y nodejs是不够的,因为这会安装nodejs的版本4,并且它安装在文件夹nodejs中,因此 WebpackDevMiddleware 找不到节点可执行文件。

关于angular - 为 Angular 项目启用 Docker 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45880460/

相关文章:

javascript - 采用 ISO 格式的每月周数(如果跨过星期四则算周数)

angular - 类型错误 : Cannot read properties of undefined (reading '<myvariable>' )

logging - 应用日志.NET Core和Docker

python - 使用 Makefile、Docker 和 Python 部署到 heroku

当tomcat服务停止时,Docker不会释放容器内的端口

angular - 自动刷新 Angular Material 模态中的iframe src

android - 寻找一种允许客户端查看 NativeScript 应用程序项目实时更新的方法

c# - Controller 方法不会从重定向中捕获对象路由

c# - 如何在新的 ASP.NET Core 中调用 Web API 非默认构造函数

c# - POST 方法总是返回 405 响应