[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. ...
随机推荐
- 防止vs编译时自动启动单元测试
Tools → Options → Live Unit Testing Pause 勾选
- css 其他
去掉border和padding占用设置元素额外的宽高,使浏览器显示的元素宽高+border+padding的总和与设置的一致,它在浏览器的总宽=40px-border-padding (默认时: 设 ...
- JavaEE 之 Mybatis
1.Mybatis a.定义:MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架 b.步骤: ①在src下创建 SqlMapConfig.xml 及 datasource.pr ...
- 李宏毅机器学习笔记5:CNN卷积神经网络
李宏毅老师的机器学习课程和吴恩达老师的机器学习课程都是都是ML和DL非常好的入门资料,在YouTube.网易云课堂.B站都能观看到相应的课程视频,接下来这一系列的博客我都将记录老师上课的笔记以及自己对 ...
- CSS3 animation 练习
css3 的动画让 html 页面变得生机勃勃,但是如何用好动画是一门艺术,接下来我来以一个demo为例,来练习css3 animation. 我们先详细了解一下animation 这个属性. ani ...
- Junit4单元测试的基本用法
看了一些Junit4的视频,简单了解了Junit4的一些基本用法,整理记录一下. 环境搭建 这里使用的开发工具是MyEclipse,首先新建一个Java工程,将Junit4的jar包引入,eclips ...
- [转]jQuery 选择器和dom操作
居然是12年的总结.... 文章地址: http://www.cnblogs.com/happyPawpaw/articles/2595092.html JQuery选择器 1.基本选择器 基本选择器 ...
- [Python]Python入坑小项目推荐- Flask example minitwit
知乎上看到的Python练手项目推荐,链接见:https://www.zhihu.com/question/29372574,不知道是我自己懒得看还是理解力不行,这些项目真的是...太大了呀~~~~ ...
- LOJ.2718.[NOI2018]归程(Kruskal重构树 倍增)
LOJ2718 BZOJ5415 洛谷P4768 Rank3+Rank1无压力 BZOJ最初还不是一道权限题... Update 2019.1.5 UOJ上被hack了....好像是纯一条链的数据过不 ...
- Android中,如何提升Layout的性能?
Layout 是 Android 应用中直接影响用户体验的关键部分.如果实现的不好,你的 Layout 会导致程序非常占用内存并且 UI 运行缓慢.Android SDK 带有帮助你找到 Layout ...