To whom it may concern,
Although in documentation is not specified, you if emulator is running in docker you need to set
- AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1
Answer was actually here: https://stackoverflow.com/a/75757385
If somone needs, this is basic docker-compose.yaml file that works.
services:
cosmosdb-emulator:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
container_name: cosmos-db-emulator
ports:
- "8081:8081"
- "10250-10255:10250-10255"
environment:
- AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1
- AZURE_COSMOS_EMULATOR_PARTITION_COUNT=3
- AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true
restart: unless-stopped
Just to point few more things.
Number of partition is reduced to 3, which means it will create 4 partitions :) (look at the running emulator log).
Also emulator is quite slow to startup, so be patient.
If you don't want to import certificate then you can do this:
CosmosClientOptions options = new()
{
HttpClientFactory = () => new HttpClient(new HttpClientHandler()
{ ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
}),
ConnectionMode = ConnectionMode.Gateway,
};
using CosmosClient client = new(
accountEndpoint: "https://localhost:8081/",authKeyOrResourceToken: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
, clientOptions: options
);
Otherwise import certificate: https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql