【发布时间】:2017-09-23 09:08:37
【问题描述】:
你好,程序员,
对于一个项目,我们创建了一个 Angular 2,这将是我们的 GUI。 此 GUI 将从托管在 Amazon Web Services (AWS) 的后端 API 获取他的数据。
GUI 也应该在 AWS 上运行,我们考虑将其作为 Docker 容器运行在 EC2 上。
GUI 在我的 PC 上运行良好,但我无法制作探测器 Docker 容器,它既不能在我的 PC 上运行,也不能在 AWS 上运行。
你们知道一个很好的教程/Hello World 项目,我可以在其中学习如何在 Docker 中创建 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
【问题讨论】:
-
我将为 docker image
ng build --production提供构建运行,并使用 nginx 或 apache 等网络服务器提供此服务。这可以防止在 docker 图像中提供整个打字稿代码 -
为什么不使用 s3?
-
@Bernhard 所以我得到我的
dist目录并将其复制到nginxnginx/html/并构建一个nginx docker容器,对吗? -
@sHamann 是的。如果您在应用程序上有大量流量,那么 taskiner 所说的最好放在 S3 或 CDN(Cloudfront)上。
-
@Bernhard 它的工作知道,你可以给这个问题一个简短的答案,这样我就可以给你一个赞成票并将你标记为解决方案?
标签: angular amazon-web-services docker amazon-ec2 dockerfile