为 Angular 项目启用 Docker 支持 [英] Enable Docker support for Angular project
问题描述
Visual Studio 2017 中是否有办法自动启用 Docker 对 asp.net-core Angular 项目的支持?创建新选项时禁用该选项.它仅适用于 Web 应用程序 (MVC).
Is there a way in Visual Studio 2017 to automatically enable Docker support for an asp.net-core Angular project? The option is disabled when creating a new one. It is only available for Web Application (MVC).
我可以在创建项目后为 Angular 项目启用 Docker 支持(项目->添加->Docker 支持),但是当我启动应用程序时,我得到一个异常,即 node.js 不可用.
I am able to Enable Docker support (Project->Add->Docker Support) for the angular project after I have created the project, but when I start the application I get an exception that node.js is not available.
System.AggregateException 发生 HResult=0x80131500 消息=一个或更多错误发生.(无法启动Node进程.解决这个:.
System.AggregateException occurred HResult=0x80131500 Message=One or more errors occurred. (Failed to start Node process. To resolve this:.
[1] 确保 Node.js 已安装并且可以在其中一个中找到PATH 目录.当前 PATH 环境变量为:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin确保 Node 可执行文件位于这些目录之一中,或更新您的 PATH.
[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] 有关原因的更多详细信息,请参阅 InnerException.)
来源= StackTrace:在System.Threading.Tasks.Task`1.GetResultCore(布尔waitCompletionNotification)在Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilderappBuilder、WebpackDevMiddlewareOptions 选项)在WebApplication3.Startup.Configure(IApplicationBuilder 应用程序,IHostingEnvironment 环境)在C:Users empDocumentsVisual Studio2017ProjectsWebApplication3Startup.cs:第 34 行
[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 empDocumentsVisual Studio
2017ProjectsWebApplication3Startup.cs:line 34
内部异常1:InvalidOperationException:启动节点失败过程.要解决这个问题:.
Inner Exception 1: InvalidOperationException: Failed to start Node process. To resolve this:.
[1] 确保 Node.js 已安装并且可以在其中一个中找到PATH 目录.当前 PATH 环境变量为:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin确保 Node 可执行文件位于这些目录之一中,或更新您的 PATH.
[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] 有关原因的更多详细信息,请参阅 InnerException.
[2] See the InnerException for further details of the cause.
内部异常2:Win32Exception:没有这样的文件或目录
Inner Exception 2: Win32Exception: No such file or directory
如果无法自动创建它,如何手动为我的 Angular 项目启用 Docker 支持?
If it is not possible to create it automatically how can I manually get the Docker support enabled for my Angular project?
推荐答案
我解决了我的问题.
我还需要在我的图像上安装 nodejs,因为 webpack 需要它.我已更改我的 Dockerfile 以安装 nodejs 版本 6
I needed to install nodejs also on my image, cause it is needed by webpack. I have changed my Dockerfile to also install nodejs version 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
没有找到节点可执行文件.
Using only RUN apt-get update && apt-get install -y nodejs
was not enough, cause this installs version 4 of nodejs and it was installed in folder nodejs
, so that the WebpackDevMiddleware
did not find the node executable.
这篇关于为 Angular 项目启用 Docker 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!