[Docker] Running Multiple Containers for an Angular, Node project

The code is from Plusight course, github link is here.

In this post, we will give a overview about how to setup Docker for a Angular, Node application, of course, you can replace Angular with any other FEF, the concept should be the same.

 

We have a normal Angular CLI generated structure:

Some differences that we add a 'server' folder and 'config' folder.

 

In serve folder, there is a docker file for Node.js:

复制代码
// node.dockerfile

FROM node:alpine

LABEL author="Dan Wahlin"

WORKDIR /var/www/angular-node-service

COPY package.json package.json
RUN npm install

COPY . .

EXPOSE 3000

ENTRYPOINT ["node", "server.js"]
复制代码

 

For 'config' folder, we have a nginx.conf file:

复制代码
server {
    listen 0.0.0.0:80;
    listen [::]:80;
    default_type application/octet-stream;

    gzip                    on;
    gzip_comp_level         6;
    gzip_vary               on;
    gzip_min_length         1000;
    gzip_proxied            any;
    gzip_types              text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers            16 8k;
    client_max_body_size    256M;

    root /usr/share/nginx/html;

    location / {
        try_files $uri $uri/ /index.html =404;
    }
}
复制代码

Mainly for handling FE Routing case.

 

The most important file is docker-compose.yml file:

复制代码
# This can be used to run a development version of the Angular and Node containers
# See the readme.md for details on changes that are required in the Angular service

# Run docker-compose build
# Run docker-compose up
# Live long and prosper

version: '3.1'

services:

  nginx:
    container_name: nginx-angular
    image: nginx-angular
    build:
      context: .
      dockerfile: nginx.dockerfile
    volumes:
      - ./dist:/usr/share/nginx/html
    ports:
      - "80:80"
      - "443:443"
    depends_on: 
      - node
    networks:
      - app-network

  node:
    container_name: angular-node-service
    image: angular-node-service
    build:
      context: ./server
      dockerfile: node.dockerfile
    environment:
      - NODE_ENV=development
    ports:
      - "3000:3000"
    networks:
      - app-network
      
  cadvisor:
    container_name: cadvisor
    image: google/cadvisor
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    ports:
      - "8080:8080"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge
复制代码

It defines 'nginx-angular', 'node' and 'cadvisor' (optional).

 

We have docker file for production:

复制代码
# This can be used to run a production version of the Angular and Node containers
# See the readme.md for details on changes that are required in the Angular service

# Run docker-compose -f docker-compose.prod.yml build
# Run docker-compose up
# Live long and prosper

version: '3.1'

services:

  nginx:
    container_name: nginx-angular
    image: nginx-angular
    build:
      context: .
      dockerfile: nginx.prod.dockerfile
    ports:
      - "80:80"
      - "443:443"
    depends_on: 
      - node
    networks:
      - app-network

  node:
    container_name: angular-node-service
    image: angular-node-service
    build:
      context: ./server
      dockerfile: node.dockerfile
    environment:
      - NODE_ENV=production
    ports:
      - "3000:3000"
    networks:
      - app-network
      
  cadvisor:
    container_name: cadvisor
    image: google/cadvisor
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
    ports:
      - "8080:8080"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge
复制代码

The way to run it is a bit different:

docker-compose -f docker-compose.prod.yml build

 

posted @   Zhentiw  阅读(932)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-04-26 [Django] Auth django app with rest api
2017-04-26 [Angular] Pluck value from Observable
2016-04-26 [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State
2016-04-26 [Angular 2] Mapping Streams to Values to Affect State
2016-04-26 [Angular 2] Managing State in RxJS with StartWith and Scan
2016-04-26 [Angular 2] Handling Clicks and Intervals Together with Merge
2016-04-26 [Angular 2] Handling Click Events with Subjects
点击右上角即可分享
微信分享提示