[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 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的更多相关文章
- [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- ...
- Errors running builder "Integrated External Tool Builder" on project
Errors during build.Errors running builder "Integrated External Tool Builder" on project p ...
- eclipse中报错:Errors running builder “Integrated External Tool Builder” on project
在eclipse构建项目的时候,一直报如下错误: Errors during build. Errors running builder "Integrated External Tool ...
- [转]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 ...
- (转)Docker - 创建 Docker overlay network (containers 通信)
原文链接: http://www.cnblogs.com/AlanWalkOn/p/6101875.html --- 创建基于Key-Value的Docker overlay network. 这样运 ...
- Docker指定multiple Insecure registry的方法
Docker如果需要从非SSL源管理镜像,需要配置Docker配置文件的insecury-registry参数,一般在如下位置修改其配置文件: * /etc/sysconfig/docker * /e ...
- 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 ...
- ASP.NET Core 2.0 in Docker on Windows Containers
安装Docker for Windows https://store.docker.com/editions/community/docker-ce-desktop-windows 要想将一个ASP. ...
- NET Core 2.0 in Docker on Windows Containers
安装Docker for Windows https://store.docker.com/editions/community/docker-ce-desktop-windows 要想将一个ASP. ...
随机推荐
- Ajax+PHP实现异步上传多张图片
Ajax+PHP实现异步上传多张图片 HTML代码 <!-- date: 2018-04-27 13:46:55 author: 王召波 descride: 多张图片上传 --> < ...
- P1052 过河 线性dp
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
- >maven-compiler-plugin的理解
在maven中项目中这个插件一直都会看见,但是一直没有认真学习一下为啥使用,现在有空就查询学习一下. 1.使用场景 下载了一些工程需要编译的时候. maven是个项目管理工具,如果我们不告诉它我们的代 ...
- IDEA创建SpringBoot项目
创建SpringBoot有三种方式: 方式一:(常用方式)
- VS项目启动后 提示ID为*******的进程当前未运行
就是VS2015中的这种问题,启动调试时,右下角根本没有IISPress图标出现.我的工程是因为突然停电,就再也调试不了了! 解决办法: 用文本编辑器打开Web项目下的{X}.csproj文件,然后查 ...
- 流网络分析系统-SNAS
流网络分析系统-SNAS SNAS,Streaming Network Analytics System (project SNAS) ,是一个收集.跟踪.存取 千万条实时路由对象的系统. 官网:ht ...
- 对于长沙互联网发展,一个外来两年Java程序员的所见所感所愿
惟楚有材,于斯为盛 本文有感于2019长沙互联网求职招聘大会,内容比较多,但都是我自己的一些所见.所感和所愿. 2019年3月的最后一天,参加2019长沙互联网求职招聘大会,看到了很多的招聘企业,也看 ...
- LoRaWAN 1.1 网络协议规范 - 5 MAC指令
LoRaWAN 1.1 网络协议规范 LoRaWAN 1.1 版本封稿很久了也没有完整啃过一遍,最近边啃边翻译,趁着这个机会把它码下来. 如果觉得哪里有问题,欢迎留言斧正. 翻译不易,转载请申明出处和 ...
- XamarinAndroid组件教程RecylerView动画组件使用动画(2)
XamarinAndroid组件教程RecylerView动画组件使用动画(2) 如果开发者要为RecylerView的子元素添加动画效果,需要使用RecyclerView类中的SetItemAnim ...
- vue中的单文件组件
之前都是在html文件中写组件的css,组件的js,组件的模板来演示vue组件的语法,下面介绍以.vue结尾的单文件组件.vue-loader是一个Webpack的loader,可以将单文件组件转换为 ...