How to deploy Angular project using Docker

How to deploy Angular project using Docker

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:
  • Detailed steps to deploy tomcat and java applications in docker
  • Detailed explanation of how to use Docker to deploy a web project and package it into an image file
  • Detailed steps for quickly deploying Node.js applications on Docker
  • Tutorial on deploying Python's Flask framework on Docker
  • Docker learning notes k8s deployment method
  • Methods for deploying MySQL services in Docker and the pitfalls encountered
  • Detailed explanation of Docker automatic deployment of tomcat
  • Detailed explanation of how to set up Go and deploy applications in Docker
  • How to deploy nextcloud network disk using docker
  • Installation and deployment of Zabbix based on Docker

<<:  Problems with changing password and connecting to Navicat when installing and using MySQL 8.0.16 under Windows 7

>>:  Example of how to embed H5 in WeChat applet webView

Recommend

How to implement concurrency control in JavaScript

Table of contents 1. Introduction to Concurrency ...

How to modify the group to which a user belongs in Linux

Modify the group to which a user belongs in Linux...

How to create components in React

Table of contents Preface Component Introduction ...

How to solve the problem that Seata cannot use MySQL 8 version

Possible reasons: The main reason why Seata does ...

CSS3 realizes the graphic falling animation effect

See the effect first Implementation Code <div ...

Using puppeteer to implement webpage screenshot function on linux (centos)

You may encounter the following problems when ins...

Detailed explanation of Linux environment variable configuration strategy

When customizing the installation of software, yo...

MySQL 5.7.21 installation and configuration method graphic tutorial (window)

Install mysql5.7.21 in the window environment. Th...

Node script realizes automatic sign-in and lottery function

Table of contents 1. Introduction 2. Preparation ...

Detailed explanation of the use of find_in_set() function in MySQL

First, let’s take an example: There is a type fie...

Detailed explanation of dynamically generated tables using javascript

*Create a page: two input boxes and a button *Cod...

This article takes you into the world of js data types and data structures

Table of contents 1. What is dynamic typing? 2. D...

Implementation steps for installing RocketMQ in docker

Table of contents 1. Retrieve the image 2. Create...