【问题标题】:How to start CosmosDB emulator with docker-compose?如何使用 docker-compose 启动 CosmosDB 模拟器?
【发布时间】:2019-08-29 15:13:49
【问题描述】:

我在 Visual Studio 中有一个 docker-compose 项目,它启动了 3 个服务。其中之一使用 cosmosdb。

我已按照https://hub.docker.com/r/microsoft/azure-cosmosdb-emulator/ 上的说明在 docker 容器中启动模拟器,它可以正常工作。

但现在我想通过 docker-compose 文件启动并运行它。以下是我目前的配置。

version: '3.4'

services:
  gateway:        
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    image: ${DOCKER_REGISTRY-}gateway
    ports:
      - "7000:80"
    depends_on:
      - servicea
      - serviceb
    build:
      context: .\ApiGateways\IAGTO.Fenix.ApiGateway
      dockerfile: Dockerfile

  servicea:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    image: ${DOCKER_REGISTRY-}servicea
    depends_on: 
      - email.db
    build:
      context: .\Services\ServiceA
      dockerfile: Dockerfile

  serviceb:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    image: ${DOCKER_REGISTRY-}serviceb
    build:
      context: .\Services\ServiceB
      dockerfile: Dockerfile

  email.db:
    image: microsoft/azure-cosmosdb-emulator
    container_name: cosmosdb-emulator
    ports:
      - "8081:8081"

当我运行docker container list 时,我可以看到容器正在运行

但对https://localhost:8081/_explorer/index.html 的请求失败。

对此非常感谢的任何帮助

【问题讨论】:

    标签: visual-studio docker .net-core docker-compose azure-cosmosdb-sqlapi


    【解决方案1】:

    问题的一部分是模拟器需要一段时间才能启动,并且在它停止等待之前有 2 分钟的超时。 我正在尝试破解它,但我没有取得太大的成功。 目前,该图像只能独立运行(通过 docker run),仅此而已。

    【讨论】:

      【解决方案2】:

      我遇到了同样的情况,但是容器是用下面的 docker-compose.yml 启动的,并且它变得可以访问了。

      我可以浏览https://localhost:8081/_explorer/index.html

      version: '3.7'
      
      services:
          cosmosdb:
              container_name: cosmosdb
              image: microsoft/azure-cosmosdb-emulator
              tty: true
              restart: always
              ports:
                  - "8081:8081"
                  - "8900:8900"
                  - "8901:8901"
                  - "8979:8979"
                  - "10250:10250"
                  - "10251:10251"
                  - "10252:10252"
                  - "10253:10253"
                  - "10254:10254"
                  - "10255:10255"
                  - "10256:10256"
                  - "10350:10350"
              volumes:
                  -  vol_cosmos:C:\CosmosDB.Emulator\bind-mount
              
      volumes:
          vol_cosmos:   
      

      可能我需要设置“tty”或“volumes”。

      【讨论】:

        【解决方案3】:

        使用 linux cosmos db 镜像,我是这样设置的:

        version: '3.4'
        
        services:
          db:
            container_name: cosmosdb
            image: "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator"
            tty: true
            restart: always
            mem_limit: 2G
            cpu_count: 2
            environment:
              - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10
              - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true
            ports:
               - "8081:8081"
               - "8900:8900"
               - "8901:8901"
               - "8979:8979"
               - "10250:10250"
               - "10251:10251"
               - "10252:10252"
               - "10253:10253"
               - "10254:10254"
               - "10255:10255"
               - "10256:10256"
               - "10350:10350"
            volumes:
               - vol_cosmos:/data/db
        
        volumes: 
          vol_cosmos:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-12-15
          • 2018-08-20
          • 2022-10-21
          • 1970-01-01
          • 2021-05-16
          • 2017-08-10
          相关资源
          最近更新 更多