[Docker] Running Multiple Containers for an Angular, Node project
2023-09-14 09:00:48 时间
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 Compose 简介
- Docker容器启动报ipv4
- 【重识云原生】第六章容器6.1.12节——Docker网络模型设计
- 分布式部署:第三章:Docker、MySQL、tomcat、Nginx、Redis部署
- 简述linux系统的目录层次结构_docker 目录
- 【好玩儿的Docker项目】用腾讯云轻量应用服务器10分钟搭建一个轻量的视频分享网站——Fireshare
- Docker安装docker-compose插件
- 【超实用】3 分钟,教你用 Docker 部署一个 Python 应用!
- 本地使用 Docker Compose 与 Nestjs 快速构建基于 Dapr 的 Redis 发布/订阅分布式应用
- 【Docker】使用docker安装部署NextCloud私人网盘
- Docker服务的拉取镜像命令(docker pull 镜像名称)
- Docker服务的删除本地镜像命令(docker rmi 镜像id)
- Docker查看容器命令(docker ps)
- zabbix自动发现监控docker中的容器
- 「 【Docker】docker的基础使用介绍(小白如何使用docker) 」
- 「 【Docker】利用宝塔docker管理器搭建为知笔记(docker安装为知笔记) 」
- Windows安装使用Docker,方便你的开发和部署(DockerDesktop篇)
- 【Docker】Linux安装Docker(极简版)
- 【Docker 系列】docker 学习六,DockerFile
- 【Docker 系列】docker 学习八,Docker 网络
- redis cluster(集群)模式-基于docker 哈希槽分区
- Docker环境下升级PostgreSQL的步骤方法详解
- docker 运行时执行bash详解程序员
- Docker容器的重启策略及docker run的–restart选项详解程序员
- 基于Docker实施Redis的简易部署(dockerredis)
- 探索Docker安装Oracle数据库的秘密(docker安装oracle)