詳解angular應(yīng)用容器化部署
Intro
我自己有做一個個人主頁,雖然效果不怎么樣(不懂設(shè)計的典型程序猿...),但是記錄了我對于前端框架及工具的一些實踐,
從開始只有一個 angularjs 制作的頁面到后面加入 less 動態(tài)寫css, gulp 自動化的將 less 文件編譯成 css 文件以及自動化的壓縮 js 和 css,到后面加入的基于 vue 和 angular 實現(xiàn),主要維護的是基于 angular 的,目前 angular 的個人主頁已經(jīng)支持 PWA(Progressive Web Application),前幾天添加了 docker 部署的支持,記錄一篇文章記錄一下。
編寫 dockerfile
完整的 dockerfile 如下:
FROM node # set working directory WORKDIR /app # install and cache app dependencies COPY . /app # install dependencies and build the angular app RUN yarn && yarn run build FROM nginx:stable-alpine # copy from dist to nginx root dir COPY --from=builder /app/dist/weihanli /usr/share/nginx/html # expose port 80 EXPOSE 80 # set author info LABEL maintainer="WeihanLi" # run nginx in foreground # https://stackoverflow.com/questions/18861300/how-to-run-nginx-within-a-docker-container-without-halting CMD ["nginx", "-g", "daemon off;"]
整個 dockerfile 可分為兩部分,第一部分是編譯 angular 應(yīng)用,生成最后要部署的文件。
第二部分則是將生成的部分拷貝到基于 nginx 的環(huán)境中,部署到 nginx 中
打包 docker 鏡像
通過 docker build 命令打包 docker 鏡像,詳細命令使用參考 https://docs.docker.com/engine/reference/commandline/build/
docker build -t weihanli/homepage .
啟動容器
docker run
通過 docker run 命令啟動一個容器,部署打包好的鏡像,詳細命令使用參考 https://docs.docker.com/engine/reference/commandline/run/
docker run -p:5200:80 --rm --name homepage-demo weihanli/homepage
docker compose
通過 docker-compose.yml 啟動容器,啟動命令: docker-compose up
更多 compose 信息參考 https://docs.docker.com/compose/compose-file
docker-compose.yml 文件如下:
version: "3"
services:
web:
image: "weihanli/homepage"
container_name: "weihanli-homepage-demo"
ports:
- "5200:80"
訪問容器中的應(yīng)用
訪問 http://localhost:5200 ,即可訪問到容器中部署的應(yīng)用
More
項目源代碼: https://github.com/WeihanLi/weihanli.github.io
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
AngularJS學(xué)習(xí)筆記之TodoMVC的分析
這篇文章主要介紹了AngularJS學(xué)習(xí)筆記之TodoMVC的分析的相關(guān)資料,需要的朋友可以參考下2015-02-02
AngularJS基礎(chǔ) ng-class-odd 指令示例
本文主要介紹AngularJS ng-class-odd 指令,這里對ng-class-odd基礎(chǔ)知識做了詳細整理,并有示例代碼和效果圖,學(xué)習(xí)AngularJS的同學(xué)可以參考下2016-08-08

