How to start CosmosDB emulator with docker-compose?

时间:2019-04-08 12:53:31

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

I've got a docker-compose project in Visual Studio which starts 3 services. One of them use cosmosdb.

I've followed the instructions on https://hub.docker.com/r/microsoft/azure-cosmosdb-emulator/ to start the emulator in a docker container and it worked.

But now I want to get it up and running through docker-compose file. Following is my current configuration.

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"

I can see the container running when I run docker container list enter image description here

But requests to https://localhost:8081/_explorer/index.html fails.

Any help on this much appreciated

3 个答案:

答案 0 :(得分: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”。

希望此评论对您或任何人有帮助。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

使用 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: