Amila
Amila

Reputation: 3816

How to start CosmosDB emulator with docker-compose?

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

Upvotes: 10

Views: 9474

Answers (4)

David Yates
David Yates

Reputation: 2220

The docker compose file that I finally got to work looks like this:

version: "3.7"
 
services: 
  cosmosdb:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
    container_name: cosmosdb
    tty: true
    mem_limit: 4G
    environment:
      - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10
      - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true
      - AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1
    ports:
      - '8081:8081' # Data Explorer
      - '10250:10250'
      - '10251:10251'
      - '10252:10252'
      - '10253:10253'
      - '10254:10254'
      - '10255:10255'
    restart: unless-stopped
    volumes:
     - vol_cosmos:/tmp/cosmos/appdata

volumes:
  vol_cosmos:

Notes

  • This thing takes between 1 and 2 minutes to start. Even if you watch the logs and see it output all of the following, it still takes another 30 seconds to minute for the explorer (https://localhost:8081/_explorer/index.html) to become accessible:
    This is an evaluation version.  There are [167] days left in the evaluation period.
    2.14.20.0 (dd7750b6)
    Copyright (C) Microsoft Corporation. All rights reserved.
    Starting
    Started 1/11 partitions
    Started 2/11 partitions
    Started 3/11 partitions
    Started 4/11 partitions
    Started 5/11 partitions
    Started 6/11 partitions
    Started 7/11 partitions
    Started 8/11 partitions
    Started 9/11 partitions
    Started 10/11 partitions
    Started 11/11 partitions
    Started
    
  • There is a minimum amount of memory necessary to run this and it's north of 3G. 4G seems to work. Failing to use enough memory will result in this error at the beginning of your logs Failed to create CoreCLR, HRESULT: 0x8007000E and another failure below the last Started that hints at a missing file Unhandled Exception: System.ComponentModel.Win32Exception: The system cannot find the file specified.
  • Now that it is storing data in volumes, you can follow Microsoft's instructions here to import the self-signed certificate into your certificate store. Failing to do this will result in errors unless you configure the CosmosClientOptions to ignore self-signed certificates (see the warning in step 10 here)

Upvotes: 0

Pavel M.
Pavel M.

Reputation: 572

Using the linux cosmos db image, I set it up like this:

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:

Upvotes: 9

salad-ja
salad-ja

Reputation: 51

I was in the same situation but the container was started with the following docker-compose.yml and it became accessible.

I can browse 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:   

Probably I needed to set "tty" or "volumes".

Upvotes: 5

Juan Carlos
Juan Carlos

Reputation: 586

Part of the problem is that the emulator takes a while to start, and there is a timeout of 2 minutes before it's just stops waiting. I'm trying to hack my way through it, but I haven't had much success. For now the image only works stand alone (via docker run) and that's it.

Upvotes: 0

Related Questions