There are two ways to deploy Angular projects with Docker. One is server-side rendering, which is described in the official documentation. The other is to compile the node image and put it into the web server. Since we are in 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 resources app.use('/', express.static(config.root)); //All routes go to index.html app.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.10 ENV PORT=4200 \ NODE_ENV=production # Install express and angular/cli RUN npm install [email protected] -g \ && npm install -g @angular/cli # Create the app directory RUN mkdir -p /app # Copy the code to the App directory COPY ./app WORKDIR /app # Install dependencies and build the program. Since I need to reverse proxy to a subdirectory, I add the base-href parameter RUN npm install && ng build --base-href /manage/ --prod EXPOSE ${PORT} ENTRYPOINT ["node", "/app/server.js"] The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
>>: Example of how to embed H5 in WeChat applet webView
Preface: Partitioning is a table design pattern. ...
Table of contents Introduction to NIS Network env...
Table of contents 1. Build local storage 2. Creat...
Basic Concepts Absolute positioning: An element b...
Preface: Vue3 has been released for a long time. ...
Use of AES encryption Data transmission encryptio...
Table of contents Preface First look at React Con...
Let's take a look at the detailed method of b...
Table of contents javascript tamper-proof object ...
1. Introduction to DockerUI DockerUI is based on ...
My environment: 3 centos7.5 1804 master 192.168.1...
I have roughly listed some values to stimulate ...
Being an operation and maintenance engineer is a ...
Table of contents Main issues solved 1. The data ...
1. Grammar: <meta name="name" content...