node+nginx-web部署

docker部署node+nginx-web微服务

操作步骤如

制作node12.4.0镜像编写dockerfile如下:

FROM node:12.4.0-stretch
#设置工作目录
WORKDIR /home/node/
#进入目录
RUN cd /usr/local/bin/
#卸载angular/cli
RUN npm uninstall -g @angular/cli
#安装
RUN npm install -g @angular/cli@7.0.7
## 新的改变

构建镜像

docker built -t node/node-server:12.4.0 .
当前目录下需要有Dockerfile文件,
创建镜像名字为node/node-server版本为12.4.0# 名字版本根据需求自己填写

显示这里就已经安装完成,红色不是报错

---> Running in 782b76336da9
npm WARN deprecated chokidar@2.0.4: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.2 (node_modules/@angular/cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ @angular/cli@7.0.7
added 268 packages from 210 contributors in 169.889s
Removing intermediate container 782b76336da9
 ---> f8fa73a2c4f7
Successfully built f8fa73a2c4f7
Successfully tagged node-te:1.0.0
这里就是已经制作完成了,

启动容器

docker run -it --name node -v /root/Lijunbao/dockerfile/node/:/home/node/ armdocker.rnd.ericsson.se/dockerhub-ericsson-remote/node:12.4.0-stretch
#挂载路径根据自己的需要填写
在刚刚挂载进去的目录去克隆 项目 https://项目地址
下载代码 git clone   地址
然后进入容器进入刚刚下载的项目木录,项目根目录执行 npm config set 这里写自己的项目注册码
在项目根目录;执行 npm install 等执行结束
在执行:ng build --prod

打包过程

root@7296b93d63d3:/home/node/front-end# ng build --prod
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
Compiling @angular/core : es2015 as esm2015
Compiling @angular/compiler/testing : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/core/testing : es2015 as esm2015
Compiling highcharts-angular : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/common/http : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/platform-browser/testing : es2015 as esm2015
Compiling @angular/forms : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
Compiling @auth0/angular-jwt : es2015 as esm2015
✔ Browser application bundle generation complete.
✔ ES5 bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.

Initial Chunk Files                      | Names                |      Size
main-es5.4c4e76c630a72fc01a2e.js         | main                 |   4.11 MB
main-es2015.4c4e76c630a72fc01a2e.js      | main                 |   4.04 MB
styles.22ee9a3597a62171cba7.css          | styles               | 897.67 kB
polyfills-es5.96c0de20f9a62a0566c1.js    | polyfills-es5        | 263.99 kB
polyfills-es2015.5d0fc56e2293859fd538.js | polyfills            | 171.41 kB
runtime-es2015.f8d01ea7e39dbb6811be.js   | runtime              |   2.44 kB
runtime-es5.f8d01ea7e39dbb6811be.js      | runtime              |   2.44 kB

                                         | Initial ES5 Total    |   5.24 MB
                                         | Initial ES2015 Total |   5.08 MB

Lazy Chunk Files                         | Names                |      Size
10-es5.350508ea78d88a2a1548.js           | -                    |   2.28 MB
10-es2015.350508ea78d88a2a1548.js        | -                    |   2.27 MB
12-es5.f671fc00b5cad54dcf50.js           | -                    |   1.16 MB
12-es2015.f671fc00b5cad54dcf50.js        | -                    |   1.15 MB
11-es5.8c67852603932ec620dc.js           | -                    | 530.40 kB
11-es2015.8c67852603932ec620dc.js        | -                    | 515.71 kB
3-es5.4d1a7c5867c1a0241f3a.js            | -                    |  78.90 kB
1-es5.5c64b19c23a9fbae3097.js            | -                    |  76.08 kB
1-es2015.5c64b19c23a9fbae3097.js         | -                    |  75.47 kB
3-es2015.4d1a7c5867c1a0241f3a.js         | -                    |  74.48 kB
4-es5.90072d9f5c39a204457c.js            | -                    |  71.89 kB
4-es2015.90072d9f5c39a204457c.js         | -                    |  70.82 kB
5-es5.5b8258eb0ccb9dc161dc.js            | -                    |  45.82 kB
5-es2015.5b8258eb0ccb9dc161dc.js         | -                    |  45.34 kB
13-es5.e5a3e5705b8f34a6e145.js           | -                    |  36.47 kB
13-es2015.e5a3e5705b8f34a6e145.js        | -                    |  32.43 kB
common-es5.9e7bcf7d35c9f71fe2e9.js       | common               |   5.45 kB
common-es2015.9e7bcf7d35c9f71fe2e9.js    | common               |   4.96 kB

Build at: 2022-03-07T06:02:50.244Z - Hash: 971d7d65ec6a6020114e - Time: 197757ms

Warning: /home/node/front-end/src/app/app.component.less exceeded maximum budget. Budget 6.00 kB was not met by 888.17 kB with a total of 894.17 kB.

Warning: /home/node/front-end/src/app/capacity/capacity.component.less exceeded maximum budget. Budget 6.00 kB was not met by 888.32 kB with a total of 894.32 kB.

Warning: /home/node/front-end/src/app/rec-rbs/rec-rbs.component.less exceeded maximum budget. Budget 6.00 kB was not met by 888.32 kB with a total of 894.32 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/button/button.component.less exceeded maximum budget. Budget 6.00 kB was not met by 879 bytes with a total of 6.86 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/dropdown/dropdown.component.less exceeded maximum budget. Budget 6.00 kB was not met by 887 bytes with a total of 6.87 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/progress-bar/progress-bar.component.less exceeded maximum budget. Budget 6.00 kB was not met by 20.59 kB with a total of 26.59 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/accordion/accordion.component.less exceeded maximum budget. Budget 6.00 kB was not met by 44.15 kB with a total of 50.15 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/checkbox/checkbox.component.less exceeded maximum budget. Budget 6.00 kB was not met by 37.46 kB with a total of 43.46 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/date/datepicker.component.less exceeded maximum budget. Budget 6.00 kB was not met by 33.58 kB with a total of 39.58 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/dialog/dialog.component.less exceeded maximum budget. Budget 6.00 kB was not met by 32.63 kB with a total of 38.63 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/gauge/gauge.component.less exceeded maximum budget. Budget 6.00 kB was not met by 44.68 kB with a total of 50.68 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/input/input.component.less exceeded maximum budget. Budget 6.00 kB was not met by 55.21 kB with a total of 61.21 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/radio/radio-button.component.less exceeded maximum budget. Budget 6.00 kB was not met by 35.13 kB with a total of 41.13 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/syntax-highlight/syntax-highlight.component.less exceeded maximum budget. Budget 6.00 kB was not met by 47.50 kB with a total of 53.50 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/table/table.component.less exceeded maximum budget. Budget 6.00 kB was not met by 64.46 kB with a total of 70.46 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/switch/switch.component.less exceeded maximum budget. Budget 6.00 kB was not met by 44.72 kB with a total of 50.72 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/tooltip/tooltip.component.less exceeded maximum budget. Budget 6.00 kB was not met by 49.01 kB with a total of 55.01 kB.
m
Warning: /home/node/front-end/src/app/eds-angular/lib/components/tabs/tabs.component.less exceeded maximum budget. Budget 6.00 kB was not met by 43.55 kB with a total of 49.55 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/tree/tree.component.less exceeded maximum budget. Budget 6.00 kB was not met by 46.27 kB with a total of 52.27 kB.

Warning: /home/node/front-end/src/app/eds-angular/lib/components/select/select.component.css exceeded maximum budget. Budget 6.00 kB was not met by 6.92 kB with a total of 12.92 kB.

Warning: /home/node/front-end/src/app/eds-angular/test.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: /home/node/front-end/src/app/eds-angular/lib/angular.module.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: /home/node/front-end/src/environments/environment.prod.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

Warning: /home/node/front-end/src/environments/environment.test.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

打包结束会有一个dist目录

nginx容器部署web

编写dockerfile

# 基础镜像
FROM nginx
# 挂载目录
VOLUME /home/deploy/frontend/
# 创建目录
RUN mkdir -p /home/deploy/frontend/
# 指定路径
WORKDIR /home/deploy/frontend/
# 复制conf文件到路径
COPY ./nginx.conf /etc/nginx/nginx.conf
# 复制html文件到路径
COPY ./dist /home/deploy/frontend/
#指定暴露端口
EXPOSE 80

nginx配置文件修改location 模块地址改成你项目地址
构建镜像目录的时候需要有nginx.conf 和dist项目包

构建容器

dcoker built -t nginx-web:1.0.0 .

docker run -it -d --name nginx-web-test -p 30005:80 -v /root/Lijunbao/dockerfile/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/deploy/frontend/dist/rvc-frontend/:/home/deploy/frontend/dist/rvc-frontend/ nginx-web:1.0.0

这里挂载目录需要写到/rvc-frontend/目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值