[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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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