SoFunction
Updated on 2025-03-10

Steps to Deploy Angular Project with Docker

There are two ways to deploy Angular projects in Docker. One is server-side rendering. This official document has already explained, and the other is to use node mirror to compile and put it into the web server. Since it is in a node environment, using express is the most convenient.

create

const express = require('express');

const app = express();
const config = {
  root: __dirname + '/dist',
  port:  || 4200
};

// Static resources('/', ());

//All routes are transferred to('*', function (req, res) {
  ( + '/');
});
(, () => {
  ("running……");
})

createDockerfile

FROM node:13.3.0-alpine3.10

ENV PORT=4200 \
  NODE_ENV=production

# Install express and angular/cliRUN npm install [email protected] -g \
  && npm install -g @angular/cli
# Create an app directoryRUN mkdir -p /app
# Copy the code to the App directoryCOPY . /app
WORKDIR /app

# Install dependencies, build the program, here, since I need to reverse proxy to the subdirectory, the base-href parameter was addedRUN npm install && ng build --base-href /manage/ --prod

EXPOSE ${PORT}

ENTRYPOINT ["node", "/app/"]

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.