为Angular项目启用Docker支持 [英] Enable Docker support for Angular project
问题描述
Visual Studio 2017中是否有一种方法可以自动为asp.net核心 Angular 项目启用Docker支持?创建新选项时,该选项被禁用.它仅可用于 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).
创建项目后,我能够为有角项目启用Docker支持(Project-> Add-> Docker Support),但是当我启动应用程序时,出现一个异常,提示node.js不可用./p>
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(Boolean
waitCompletionNotification)
Microsoft.AspNetCore.Builder.WebpackDevMiddleware.UseWebpackDevMiddleware(IApplicationBuilder
appBuilder,WebpackDevMiddlewareOptions选项),网址为
WebApplication3.Startup.Configure(IApplicationBuilder应用,
IHostingEnvironment env)在
C:\ Users \ temp \ Documents \ Visual Studio
2017 \ Projects \ WebApplication3 \ Startup.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\temp\Documents\Visual Studio
2017\Projects\WebApplication3\Startup.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屋!