cosmosdb emulator linux container - cannot connect

Georgios Voulgarakis 0 Reputation points Microsoft Employee
2023-04-03T09:08:55.5+00:00

Using docker with linux containers

using cosmos emulator linux image:

cosmosdb:  
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest  
tty: true  
platform: linux  
mem_limit: 3G  
cpu_count: 4  
environment:    
AZURE_COSMOS_EMULATOR_PARTITION_COUNT: 10    
AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: true    
ports:    
- '8081:8081'    
- '8900:8900'    
- '8901:8901'    
- '8902:8902'    
- '10250:10250'    
- '10251:10251'   
- '10252:10252'   
- '10253:10253'    
- '10254:10254'    
- '10255:10255'    
- '10256:10256'    
- '10350:10350'

Trying to connect using the dotnet SDK, but nothing happens...

// Allow CosmosDB emulator self-signed certificate in DEBUG mode
// Use Gateway modecosmosClientOptions = new CosmosClientOptions{    HttpClientFactory = () => new HttpClient(new HttpClientHandler    {        ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator    }),    ConnectionMode = ConnectionMode.Gateway};

Also when I try to create a container/db via the UI, I am getting a "failed to fetch error":
(see attachment)

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,904 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2023-04-03T10:15:23.2533333+00:00

    Hi Georgios Voulgarakis •,

    Welcome to Microsoft Q&A forum and thanks for using Azure services.

    As I understand, you are facing connectivity issues in cosmos db emulator linux container.

    • Ensure the emulator is running with the following command:
    docker ps --all
    
    
    • Verify that the specific emulator container is in a running state.
    • Verify that no other applications are using emulator ports: 8081 and 10250-10255.
    • Verify that the container port 8081, is mapped correctly and accessible from an environment outside of the container.
       netstat -lt
       
    
    • Try to access the endpoint and port for the emulator using the Docker container's IP address instead of "localhost".
    • Make sure that the emulator self-signed certificate has been properly added to KeyChain.
    • For Java applications, make sure you imported the certificate to the Java Certificates Store section.
    • For .NET applications you can disable TLS/SSL validation:
       CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
       {
           HttpClientFactory = () =>
           {
               HttpMessageHandler httpMessageHandler = new HttpClientHandler()
               {
                   ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
               };
       
               return new HttpClient(httpMessageHandler);
           },
           ConnectionMode = ConnectionMode.Gateway
       };
       
       
       CosmosClient client = new CosmosClient(endpoint, authKey, cosmosClientOptions);
    

    Also make sure current Docker Host processor type is compatible with our Docker image.

    Refer to the documentation here for complete troubleshooting steps.

    Please let us know if these steps helped. If not, please let us know so that we can further investigate. Thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.