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

时间:2022-09-15 09:23:23

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:

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

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 ENTRYPOINT ["node", "server.js"]

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

server {
listen 0.0.0.0:;
listen [::]:;
default_type application/octet-stream; gzip on;
gzip_comp_level ;
gzip_vary on;
gzip_min_length ;
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 8k;
client_max_body_size 256M; root /usr/share/nginx/html; location / {
try_files $uri $uri/ /index.html =;
}
}

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

[Docker] Running Multiple Containers for an Angular, Node project的更多相关文章

  1. [NPM] Use a shorthand syntax for running multiple npm scripts with npm-run-all

    Running multiple scripts in series or in parallel can become very verbose. Using a tool such as npm- ...

  2. Errors running builder "Integrated External Tool Builder" on project

    Errors during build.Errors running builder "Integrated External Tool Builder" on project p ...

  3. eclipse中报错:Errors running builder “Integrated External Tool Builder” on project

    在eclipse构建项目的时候,一直报如下错误: Errors during build. Errors running builder "Integrated External Tool ...

  4. [转]How to Add Bootstrap to an Angular CLI project

    本文转自:https://loiane.com/2017/08/how-to-add-bootstrap-to-an-angular-cli-project/ In this article we w ...

  5. (转)Docker - 创建 Docker overlay network (containers 通信)

    原文链接: http://www.cnblogs.com/AlanWalkOn/p/6101875.html --- 创建基于Key-Value的Docker overlay network. 这样运 ...

  6. Docker指定multiple Insecure registry的方法

    Docker如果需要从非SSL源管理镜像,需要配置Docker配置文件的insecury-registry参数,一般在如下位置修改其配置文件: * /etc/sysconfig/docker * /e ...

  7. Running multiple instances of Xamarin Studio on a Mac

    I love developing software on my MacBook Air! I got the latest version with the maximum possible spe ...

  8. ASP.NET Core 2.0 in Docker on Windows Containers

    安装Docker for Windows https://store.docker.com/editions/community/docker-ce-desktop-windows 要想将一个ASP. ...

  9. NET Core 2.0 in Docker on Windows Containers

    安装Docker for Windows https://store.docker.com/editions/community/docker-ce-desktop-windows 要想将一个ASP. ...

随机推荐

  1. IP釋放、清除、以及刷新DNS

    Windows 10 於桌面按住 Windows  + X 按鍵. 選擇 Command Prompt (以管理員執行). 在彈跳視窗中輸入 ipconfig /release. 等待數秒回報此 IP ...

  2. HTML5日期输入类型(date)

    在很多页面和web应用中都有输入日期和时间的地方,最典型的是订飞机票,火车票,酒店,批萨等网站. 在HTML5之前,对于这样的页面需求,最常见的方案是用Javascript日期选择组件.这几乎是无可争 ...

  3. 虚拟机centos6.5 --开放端口

    系统:centos6.5 1.查看端口开放情况 /etc/init.d/iptables status 2.开启端口 /sbin/iptables -I INPUT -p tcp --dport -j ...

  4. CGI相关概念

    common gateway interface 通用网关接口 可以让客户端从浏览器向执行在服务器上的程序请求数据.CGI描述了客户端和服务器程序之间传输数据的一种标准. 编程语言perl是一种被广泛 ...

  5. C++中用辗转相除法求两个数的最大公约数和最小公倍数

    两个数的最大公约数:不能大于两个数中的最小值,算法口诀:小的给大的,余数给小的,整除返回小的,即最大公约数,(res=max%min)==0?  max=min,min=res return min; ...

  6. Babel presets stage

    在一些新框架的代码中,常基于es6/7标准来书写代码.鉴于这些标准被没有被浏览器广泛支持,我们一般使用babel来将使用e6/7标准书写的代码降级编译(或者说转译)为浏览器可解析的es3/5代码. 以 ...

  7. [POJ1006]生理周期 (中国剩余定理)

    蒟蒻并不会中国剩余定理 交的时候还出现了PE的错误 下面是AC代码 #include<iostream> #include<cstdio> using namespace st ...

  8. 为DataGridView增加鼠标滚轮功能

    #region 鼠标滚动 [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "Wi ...

  9. 【CF886E】Maximum Element DP

    [CF886E]Maximum Element 题意:小P有一个1-n的序列,他想找到整个序列中最大值的出现位置,但是他觉得O(n)扫一遍太慢了,所以它采用了如下方法: 1.逐个遍历每个元素,如果这个 ...

  10. Java典型应用彻查1000例:图形与网络游戏开发 PDF 扫描版&lbrack;68M&rsqb;

    <Java典型应用彻查1000例·图形与网络游戏开发>实例丰富,编排合理,可以让有初级Java基础的读者,从陌生到完全熟练地设计网络游戏,进而掌握3D立体绘图方法,适合作为Java网络游戏 ...