[英]How to setup deploy nodejs app using jenkins docker container in aws ec2
[英]Angular 2 app deploy in a docker Container running on AWS
各位程序員好,
對於一個項目,我們創建了一個 Angular 2,它將作為我們的 GUI。 該 GUI 將從 Amazon Web Services (AWS) 托管的后端 API 獲取數據。
GUI 也應該在 AWS 上運行,我們考慮將其作為 EC2 上的 Docker 容器運行。
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
從帶寬、關注點分離和混淆的角度來看,創建項目的構建而不是使用整個angular-cli
功能來為客戶端服務更為實用。
為什么:
ng serve
更適用於開發環境,防止在開發過程中專注於設置網絡服務器、后端代理等。 但除此功能外, angular-cli
還提供了簡單的構建工具。
創建構建:
ng build --prod
收集所有依賴項並創建一個包含整個應用程序的dist
文件夾。
此文件夾的內容可以復制/部署到Apache 、 nginx或IIS等 Web 服務器上
邊注:
當您的應用程序未在您的域根(例如www.my.domain.com/subfolder )上運行時,為構建指定base href
屬性也很重要。 例如:
ng build --prod --base-href /subfolder/
然后您的應用程序將在www.my.domain.com/subfolder/上正常運行,並加載圖像等所有資產。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.