I have a cosmos db container with this docker compose specs:
version: '3.8'
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:
The servive works great inside the docker network! The problem is accessing from the host -> container, here a simple c# code to reproduce the problem:
var cosmosClient = new CosmosClient(
"AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
new CosmosClientOptions()
{
HttpClientFactory =() =>
{
HttpMessageHandler httpMessageHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
return new HttpClient(httpMessageHandler);
},
ConnectionMode = ConnectionMode.Gateway
}
);
var container = cosmosClient.GetContainer("MyDb", "MyContainer");
var containers = await container.ReadContainerAsync(); // the executing stucks here
containers.StatusCode.Dump();
Cosmos docs says that I need to run the emulator with the arguments allownetworkaccess and key, but how can I add this to the docker compose?
The strange thing is that I tried to make an http GET from the host to the container endpoint dbs and for my surprise I get the http 200 and the result!
Any help?