[Docker] Running Multiple Containers for an Angular, Node project
2023-09-14 08:59:14 时间
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
相关文章
- Docker从入门到精通系列(1)---第一个web应用
- Nginx传统方法安装(非Docker)
- 微服务之springCloud-docker-feign-hystrix-ribbon(七)
- docker探索-Win10 Docker 安装使用(一)
- MacOS Docker 安装
- [Angular CLI] Build application without remove dist folder for Docker Volume
- [Angular 2] ROUTING IN ANGULAR 2 REVISITED
- 运维基础之Docker(2)通过docker部署zookeeper nginx tomcat java redis kibana/elasticsearch/logstash mysql kafka mesos/marathon ftp git
- 前后端项目部署-6, flask+Gunicorn+gevent+supervisor+nginx+redis+mysql+mongodb+vue,docker-compose部署
- Ubuntu安装Docker引擎和支持HTTPS的docker-registry服务
- Docker -v 数据卷挂载nginx文件
- 启动docker容器时报错:iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 5000 -j DNAT -
- Angular 项目里 angular.json 文件内容的学习笔记
- Docker入门系列之二:使用dockerfile制作包含指定web应用的镜像
- 【云原生 | Kubernetes 系列】Docker 面试题2则--取数据库连接数和docker-compose
- 80.第十七章 企业级容器技术docker -- Docker 数据管理(八)
- 【云原生之Docker实战】使用docker部署Homebox内网测速工具
- 【云原生之Docker实战】使用docker部署ubuntu系统测试环境
- 【云原生之Docker实战】部署docker管理平台shipyard
- 【云原生之Docker实战】使用docker部署o2oa企业OA平台
- docker命令 参数含义
- 如何使用Docker实现分布式Web自动化?【一看就会系列】
- docker 卸载旧版本
- Ubuntu docker 安装
- Docker----对已经存在的docker如何修改时区
- ASP.NET Core微服务(七)——【docker部署linux上线】(RDS+API接口测试部分)
- Docker 镜像使用(拉取、查看、使用、删除)
- Docker学习笔记16:docker实例之安装 Nginx
- Docker学习笔记10:docker使用之仓库管理
- 【Docker系列】6.使用docker-compose安装nginx
- Docker学习笔记(三):查看docker 拉取的镜像位置和位置参数
- 云原生之使用Docker部署docker-compose-ui工具
- docker 修改容器时区