How to start CosmosDB emulator with docker-compose?
Asked Answered
S

3

10

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

Soupspoon answered 8/4, 2019 at 12:53 Comment(0)
S
9

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:
Synthiasyntonic answered 22/6, 2021 at 17:39 Comment(2)
Did you get it to work with the MongoDB api endpoint?Preceptor
How do you deal with the certificate?Bagdad
H
5

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".

Heth answered 7/7, 2020 at 2:57 Comment(0)
S
0

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.

Sedimentary answered 9/5, 2019 at 20:13 Comment(2)
Have you considered including the depends on so that your image will not start until cosmos emulator startsKelso
I stopped using the cosmos image and instead using mongo. Then in azure I can just crate a cosmos db with mongo api. This works for other API surface you want. So you locally work with a well known docker image, and then when deployed use anything that has the same API.Sedimentary

© 2022 - 2024 — McMap. All rights reserved.