Azure / azure-cosmos-db-emulator-docker

This repo serves as hub for managing issues, gathering feedback, and having discussions regarding the Cosmos DB Emulator Docker.
https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql
MIT License
153 stars 46 forks source link

Linux docker container runs but function app CosmosDBTrigger does nothing. Windows msi does work. #82

Open Barsonax opened 10 months ago

Barsonax commented 10 months ago

Describe the bug Linux docker container runs but function app CosmosDBTrigger does nothing. Windows msi does work.

To Reproduce Steps to reproduce the behavior:

  1. Start the cosmosdb container using this docker compose file

    services:
    cosmosdb:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
    container_name: "cosmosdb"
    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"
  2. Ensure https certificate is trusted (NOTE: everytime you restart the container it seems to regenerate the cert so you need to trust it again, personally I find this gives a bad developer experience. It should reuse the same cert or even better give a option to ignore ssl errors in azure functions).

  3. Run a azure function locally that uses CosmosDBTrigger. Notice how nothing happens, no errors are logged either. Leases are not created even if CreateLeaseContainerIfNotExists is set to true.

Expected behavior Atleast an error describing what went wrong or even better just make it work like the windows msi emulator.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Docker Images Used:

**Arguments && Environment variables to start Docker:

Docker Environment

Barsonax commented 10 months ago

When I use network_mode: host it does work so this seems to be networking related. Not clear to me yet what exactly but the docs don't mention anything about this.

This is not a real solution though as host networking has its own problems.

Barsonax commented 10 months ago

I managed to get it to work with this docker compose definition:

services:
  cosmosdb:
    image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
    container_name: "cosmosdb"
    environment:
      - AZURE_COSMOS_EMULATOR_PARTITION_COUNT=1
      - AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true
      - AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1
    ports:
      - 8081:8081

Hope this will help anyone who stumbles on this but the real fix is to update the docs.

AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE is apparently needed when running in a docker container. Probably because its in a different subnet. Was quite hard to find though that this is the fix.

I also noticed that it has to run on port 8081. If you let say map a different port to 8081 inside the container your app will simply hang for minutes.