'Cosmos SDK experiences timeouts if mapped ports in docker-compose file differ
This question was originally asked by ben-graffle on Github.
I'm posting here to widen the audience for this question.
Receiving 408 timeouts with the cosmos C# SDK with specific port mapping configurations in a docker-compose file
docker compose that works
cosmos:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
container_name: cosmos
ports:
- 8081:8081
- 10251:10251
- 10252:10252
- 10253:10253
- 10254:10254
expose:
- "8081"
- "10251-10255"
environment:
- AZURE_COSMOS_EMULATOR_PARTITION_COUNT=6
- AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false
- AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=${LOCALIPADDRESS}
docker compose that does not work
cosmos:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
container_name: cosmos
expose:
- "8081"
- "10251-10255"
ports:
- 8082:8081
- 10252:10251
- 10253:10252
- 10254:10253
- 10255:10254
environment:
- AZURE_COSMOS_EMULATOR_PARTITION_COUNT=6
- AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false
- AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=${LOCALIPADDRESS}
Function call that throws exception
var httpMessageHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
{
HttpClientFactory = () => new HttpClient(httpMessageHandler),
ConnectionMode = ConnectionMode.Gateway,
Serializer = new CosmosJsonNetCustomSerializer(),
RequestTimeout = TimeSpan.FromMinutes(3)
};
using CosmosClient client = new CosmosClient(cosmosEndpoint, COMSOS_KEY, cosmosClientOptions);
var db = await client.CreateDatabaseIfNotExistsAsync("GraffleMinerDatabase", 4000, null, CancellationToken.None);
The first docker-compose yaml works and the second does not. Receiving the following error
Unhandled exception. Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: RequestTimeout (408); Substatus: 0; ActivityId: 2f24681b-db18-44aa-afc8-e12ba02d8930; Reason: (GatewayStoreClient Request Timeout. Start Time UTC:03/29/2022 22:28:56; Total Duration:36015.4719 Ms; Request Timeout 20000 Ms; Http Client Timeout:180000 Ms; Activity id: 2f24681b-db18-44aa-afc8-e12ba02d8930;);
The reason I am looking to map the ports differently is i need to have two cosmos emulator docker containers running simultaneously.
Any assistance/insight would be greatly appreciated.
Solution 1:[1]
The following method can help to solve the issue.
As we know that the ports will be the concatenation of the ports in all compose files, I would be a suggestable pattern by creating a new docker-compose.dev.yml file which contains all development port mappings, removing them from the base docker-compose.yml file.
docker-compose.override.yml will not be applied if you manually specify another override file (e.g. docker-compose -f docker-compose.yml -f docker-compose.prod.yml)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SairamTadepalli-MT |
