• Dapr牵手.NET学习笔记:用dockercompose部署服务


      上一篇聊到用两个物理机(一个win,一个mac)来部署dapr和服务 ,实现order调用pay的负载均衡。本篇说一下在windows上的docker部署这三个服务,达到与上一篇的效果。

      三个服务的部署架构是这样的

     首先要把OrderSystem(服务端口80)项目docker化,Dockerfile内容为:

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
    WORKDIR /app
    EXPOSE 80
    
    FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
    WORKDIR /src
    COPY ["/OrderSystem/OrderSystem.csproj", "OrderSystem/"]
    RUN dotnet restore "OrderSystem/OrderSystem.csproj"
    COPY . .
    WORKDIR "/src/OrderSystem"
    RUN dotnet build "OrderSystem.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "OrderSystem.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "OrderSystem.dll"]

    其实要把PaymentSystem(服务端口80)项目docker化,Dockerfile内容为:

    FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
    WORKDIR /app
    EXPOSE 80
    
    FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
    WORKDIR /src
    COPY ["/PaymentSystem/PaymentSystem.csproj", "PaymentSystem/"]
    RUN dotnet restore "PaymentSystem/PaymentSystem.csproj"
    COPY . .
    WORKDIR "/src/PaymentSystem"
    RUN dotnet build "PaymentSystem.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "PaymentSystem.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "PaymentSystem.dll"]

    同时再添加一个docker-compose项目(右键 OrderSystem或PaymentSystem,Add,选择Container Orchestrator Support即可),命名为B2C,目录结构如下:

     其中docker-compose.yml内容如下

    version: '3.4'
    
    services:
      ordersystem:
        image: ${DOCKER_REGISTRY-}ordersystem
        build:
          context: ../
          dockerfile: /OrderSystem/Dockerfile
        ports:
          - "3500:3500"
        volumes:   
          - ../OrderSystem:/OrderSystem   
      ordersystem-dapr:
         image: "daprio/daprd:latest"
         command: [ "./daprd", "-app-id", "order", "-app-port", "80" ]
         depends_on:
           - ordersystem
         network_mode: "service:ordersystem"
         
      paymentsystem1:
        image: ${DOCKER_REGISTRY-}paymentsystem
        build:
          context: ../
          dockerfile: /PaymentSystem/Dockerfile
        ports:
          - "3601:3500"
        volumes:   
          - ../PaymentSystem:/PaymentSystem         
      paymentsystem1-dapr:
         image: "daprio/daprd:latest"
         command: [ "./daprd", "-app-id", "pay", "-app-port", "80" ]
         depends_on:
           - paymentsystem1
         network_mode: "service:paymentsystem1"
    
      paymentsystem2:
        image: ${DOCKER_REGISTRY-}paymentsystem
        build:
          context: ../
          dockerfile: /PaymentSystem/Dockerfile
        volumes:   
          - ../PaymentSystem:/PaymentSystem            
        ports:
          - "3602:3500"
      paymentsystem2-dapr:
         image: "daprio/daprd:latest"
         command: [ "./daprd", "-app-id", "pay", "-app-port", "80" ]
         depends_on:
           - paymentsystem2
         network_mode: "service:paymentsystem2"

      为了使PaymentSystem部署多个副本,我在docker-compose.yml中配置了paymentsystem1和paymentsystem2,它们使用的都是PaymentSystem项目的信息。关于docker-compose就不多说了。

    进入B2C目录,启动三个服务,命令如下:

    docker-compose up -d

    就会在docker中启动三个服务,一个order,两个pay,如下:

     

    看一下结果吧,同样是postman,输入localhost:3500/v1.0/invoke/order/method/order,就会看到pay会轮询调用。

    paymentsystem1

     paymentsystem2

     

      想要更快更方便的了解相关知识,可以关注微信公众号 
     

     

  • 相关阅读:
    asp.net各种视频格式转换为flv格式代码
    万能播放器代码
    FlashPaper安装及使用方法
    falsh播放器代码(播放器收集)
    正则表达式
    Windows API介绍及用法:CreateFileMapping和MapViewOfFile函数(进程间数据共享)
    Win7 魔兽争霸打开时最小化
    CSV文件格式
    Excel
    asp.net先于iis安装导致iis不能解析aspx的问题(Failed to access IIS metabase,IISメタベースにアクセスできませんでした)
  • 原文地址:https://www.cnblogs.com/axzxs2001/p/16043049.html
Copyright © 2020-2023  润新知