调用CosmosClient方法时Cosmos DB Docker容器无响应
Linux版Cosmos DB Docker容器代码连接无响应问题
更新:Linux Mint和Windows系统下使用该容器均出现相同问题,宿主操作系统并非影响因素。
已成功安装并运行容器,可正常访问本地模拟器UI(https://localhost:8081/_explorer/index.html),能在此创建数据库、容器并添加数据。
但通过代码连接时出现问题,使用标准连接字符串:
AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
最初遇到SSL问题,已通过导入SSL证书解决,但核心问题是:解决SSL问题后,所有操作均无响应。
尝试过创建数据库和容器、手动创建后添加数据、加载手动创建的条目,所有场景下,调用CosmosClient的以下方法时均失败:
- CreateDatabaseIfNotExistsAsync
- ReadItemAsync
- UpsertItemAsync
无任何错误提示,代码直接挂起,甚至不会超时,可持续运行超一小时无动作。
排查后发现调试输出窗口循环出现如下内容(已编辑简化):
DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1 DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1 DocDBTrace Information: 0 : Resolving Master service address, forceMasterRefresh: False, currentMaster: DocDBTrace Warning: 0 : ClientRetryPolicy: Gateway HttpRequestException Endpoint not reachable. Failed Location: https://172.17.0.4:8081/; ResourceAddress: dbs/brain-store DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.4:8081/ unavailable for read DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.4:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 04/22/2024 15:17:17 DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.4:8081/ unavailable for Write DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.4:8081/ unavailable for Write added/updated to unavailableEndpoints with timestamp 04/22/2024 15:17:17 DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Resolving Master service address, forceMasterRefresh: False, currentMaster: Exited Thread 94863 Exited Thread 95169 Exited Thread 95168 DocDBTrace Warning: 0 : ClientRetryPolicy: Gateway HttpRequestException Endpoint not reachable. Failed Location: https://172.17.0.4:8081/; ResourceAddress: dbs/brain-store DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.4:8081/ unavailable for read DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.4:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 04/22/2024 15:17:28 DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.4:8081/ unavailable for Write DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.4:8081/ unavailable for Write added/updated to unavailableEndpoints with timestamp 04/22/2024 15:17:28 DocDBTrace Information: 0 : Resolving Master service address, forceMasterRefresh: False, currentMaster: Exited Thread 95167 Exited Thread 94872 DocDBTrace Warning: 0 : ClientRetryPolicy: Gateway HttpRequestException Endpoint not reachable. Failed Location: https://172.17.0.4:8081/; ResourceAddress: dbs/brain-store DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.4:8081/ unavailable for read DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.4:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 04/22/2024 15:17:38 DocDBTrace Information: 0 : GlobalEndpointManager: Marking endpoint https://172.17.0.4:8081/ unavailable for Write DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.17.0.4:8081/) ReadEndpoints = (https://172.17.0.4:8081/) DocDBTrace Information: 0 : Endpoint https://172.17.0.4:8081/ unavailable for Write added/updated to unavailableEndpoints with timestamp 04/22/2024 15:17:38
尝试ping 172.17.0.4,发现该地址不在本地网络中,推测仅在Docker容器内部有效。问题在于,模拟器指示代码连接一个不存在的端点,代码该如何连接?
Docker容器配置
环境变量:
- AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: 1
- PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
端口映射:
- 10250/tcp → 0.0.0.0:10250
- 10251/tcp → 0.0.0.0:10251
- 10252/tcp → 0.0.0.0:10252
- 10253/tcp → 0.0.0.0:10253
- 10254/tcp → 0.0.0.0:10254
- 10255/tcp → 0.0.0.0:10255
- 8081/tcp → 0.0.0.0:8081
是否遗漏了什么配置?
内容的提问来源于stack exchange,提问作者Keith Jackson
相关产品推荐
相关产品推荐

