Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Method steps for deploying an Angular project using Docker

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

There are two ways for Docker to deploy an Angular project, one is server-side rendering, which is described in the official document, and the other is to use a node image to compile and put it into the web server. Because of the node environment, it is most convenient to use express.

Create server.js

Const express = require ('express'); const app = express (); const config = {root: _ dirname +' / dist', port: process.env.PORT | | 4200}; / / static resource app.use ('/', express.static (config.root)); / / all routes go to index.htmlapp.all ('*', function (req, res) {res.sendfile (config.root +'/ index.html');}) App.listen (config.port, () = > {console.log ("running.") ;})

Create Dockerfile

FROM node:13.3.0-alpine3.10ENV PORT=4200\ NODE_ENV=production# install express and angular/cliRUN npm install express@4.17.1-g\ & & npm install-g @ angular/cli# create the app directory RUN mkdir-p / app# copy the code to the App directory COPY. / appWORKDIR / app# installation depends on building the program. Here, since I need to reverse proxy to the subdirectory, I added the base-href parameter RUN npm install & & ng build-- base-href / manage/-- prodEXPOSE ${PORT} ENTRYPOINT ["node", "/ app/server.js"]

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report