Angular 2应用程序部署在AWS上运行的Docker容器中

你好程序员,

对于一个项目,我们创build了一个Angular 2,它将成为我们的GUI。 这个GUI将从Amazon Web Services(AWS)托pipe的后端API获取他的数据。

GUI也应该在AWS上运行,我们将把它作为EC2上的Docker容器运行。

GUI在我的电脑上工作正常,但我不能制作一个探测器的Docker容器,它既不能在我的电脑上也不能在AWS上工作。

你们知道一个很好的教程/ Hello World项目,我可以学习如何在Docker中创build一个Angular 2应用程序吗?

一些更多的信息如何即时尝试这样做:

我的Dockerfile

# Create image based off of the official Node 6 image FROM node:6 # Create a directory where our app will be placed RUN mkdir -p /usr/src/app # Change directory so that our commands run inside this new dir WORKDIR /usr/src/app # Copy dependency definitions COPY package.json /usr/src/app # Install dependecies RUN npm install # Get all the code needed to run the app COPY . /usr/src/app # Expose the port the app runs in EXPOSE 4200 # Serve the app CMD ["npm", "start"] 

改变package.json

  { ... "scripts": { "start": "ng serve -H 0.0.0.0", ... }, ... } 

运行docker build -t gui:test .

运行docker run --name gui -p 4200:4200 gui:test

如果我做了正确的localhost:4200应该显示我运行Angluar 2应用程序,他不。

编辑:从恶魔与港给出的IP不工作也192.168.99.100:4200

创build项目的构build更加实际,而不是使用整个angular-clifunction来从带的angular度来分离关注和混淆,从而为客户端服务。

为什么:

ng serve更是一个开发上下文,防止在开发过程中集中build立一个web服务器,后台代理等。 但除此之外, angular-cli还提供了简单的构build工具。

创build一个构build:

ng build --prod收集所有依赖关系,并创build一个包含整个应用程序的dist文件夹。

这个文件夹的内容可以复制到ApachenginxIIS等networking服务器上

边注:

当您的应用程序未运行在您的域名根目录(例如http://www.my.domain.com/subfolder)时,指定构build的base href属性也很重要。 例如:

ng build --prod --base-href /subfolder/

然后,您的应用程序将在http://www.my.domain.com/subfolder/上正确运行,并且所有资源(如图像等)都会被加载。