docker-compose之.netcore+mysql+Ocelot多容器部署
2022/5/24 2:19:50
本文主要是介绍docker-compose之.netcore+mysql+Ocelot多容器部署,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
继上节.NetCoreApi容器与MySql容器互联继续讲解,主要增加了Ocelot网关。
项目结构
编写 docker-compose.yml 文件
version: '3' services: db: image: mysql:5.5 command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci container_name: db restart: always ports: - "3306:3306" environment: - MYSQL_PASSWORD=123456 - MYSQL_ROOT_PASSWORD=123456 - MYSQL_USER=yak networks: - dev volumes: - "./db:/var/lib/mysql" - "./conf/my.cnf:/etc/my.cnf" - "./init:/docker-entrypoint-initdb.d/" gateway: container_name: gateway build: context: ./OcelotGateway dockerfile: Dockerfile ports: - 80:80 environment: TZ: "Asia/Shanghai" ASPNETCORE_ENVIRONMENT: "Production" links: - a - b - c - d networks: - dev a: container_name: businessa hostname: Business_A build: context: ./BusinessProjectA dockerfile: Dockerfile ports: - 81:80 environment: TZ: "Asia/Shanghai" ASPNETCORE_ENVIRONMENT: "Production" networks: - dev b: container_name: businessb hostname: Business_B build: context: ./BusinessProjectA dockerfile: Dockerfile ports: - 82:80 environment: TZ: "Asia/Shanghai" ASPNETCORE_ENVIRONMENT: "Production" networks: - dev c: container_name: businessc hostname: Business_C build: context: ./BusinessProjectA dockerfile: Dockerfile ports: - 83:80 environment: TZ: "Asia/Shanghai" ASPNETCORE_ENVIRONMENT: "Production" networks: - dev - pro d: container_name: businessd hostname: Business_D build: context: ./Yak.Docker.Test dockerfile: Dockerfile ports: - 84:80 environment: TZ: "Asia/Shanghai" ASPNETCORE_ENVIRONMENT: "Production" networks: - dev - pro e: container_name: businesse hostname: Business_E build: context: ./Yak.DockerCompose.Api dockerfile: Dockerfile ports: - 85:80 environment: TZ: "Asia/Shanghai" ASPNETCORE_ENVIRONMENT: "Production" networks: - dev - pro depends_on: - db networks: dev: driver: bridge pro: driver: bridge
编写 ocelot.json 文件
{ "Routes": [ { "UpstreamPathTemplate": "/business/{url}", "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Patch", "Options", "Head", "Trace", "Connect", "Purge", "None" ], "DownstreamPathTemplate": "/{url}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Port": "80", "Host": "businessa" }, { "Port": "80", "Host": "businessb" }, { "Port": "80", "Host": "businessc" } ], "LoadBalancerOptions": { "Type": "LeastConnection", "Exact": true } }, { "UpstreamPathTemplate": "/weather/{url}", "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Patch", "Options", "Head", "Trace", "Connect", "Purge", "None" ], "DownstreamPathTemplate": "/{url}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Port": "80", "Host": "businessd" } ], "LoadBalancerOptions": { "Type": "LeastConnection", "Exact": true } }, { "UpstreamPathTemplate": "/user/{url}", "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete", "Patch", "Options", "Head", "Trace", "Connect", "Purge", "None" ], "DownstreamPathTemplate": "/{url}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Port": "80", "Host": "businesse" } ], "LoadBalancerOptions": { "Type": "LeastConnection", "Exact": true } } ], "DynamicReRoutes": [], "Aggregates": [], "GlobalConfiguration": { "BaseUrl": "http://localhost" } }
代码拷贝到Linux系统中
启动 docker-compose
docker-compose up -d --build
查看
docker-compose ps
访问 http://192.168.192.138/user/User/Get
这篇关于docker-compose之.netcore+mysql+Ocelot多容器部署的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具