【问题标题】:Failed to Connect to the Azure Cosmos DB Emulator running Docker using Mongo无法使用 Mongo 连接到运行 Docker 的 Azure Cosmos DB 模拟器
【发布时间】:2019-12-09 15:35:43
【问题描述】:

我在使用在 Docker 中运行的 Azure Cosmos 模拟器时遇到问题。运行我的应用程序时,尝试连接到数据库时出现以下错误:

connection error: MongoNetworkError: failed to connect to server [localhost:10255] on first connect [Error: connect ETIMEDOUT 127.0.0.1:10255
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
  name: 'MongoNetworkError',
  [Symbol(mongoErrorContextSymbol)]: {}
}]

设置

按照Running on Docker instructions,我拉了图就跑了

md %LOCALAPPDATA%\CosmosDBEmulator\bind-mount

docker run --name azure-cosmosdb-emulator --memory 2GB --mount "type=bind,source=%LOCALAPPDATA%\CosmosDBEmulator\bind-mount,destination=C:\CosmosDB.Emulator\bind-mount" --interactive --tty -p 8081:8081 -p 8900:8900 -p 8901:8901 -p 8902:8902 -p 10250:10250 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -p 10255:10255 -p 10256:10256 -p 10350:10350 mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator

配置

  1. 我尝试了几种不同的连接字符串,但都没有成功,我使用的主要连接字符串是:
mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true
  1. 我可以通过https://localhost:8081/_explorer/index.html 访问资源管理器,因此模拟器正在运行。

  2. 我在应用中使用猫鼬

【问题讨论】:

    标签: azure azure-cosmosdb azure-cosmosdb-mongoapi


    【解决方案1】:

    经过一番沮丧的挠头后,我找到了解决方案!根据模拟器指令的Docker container page,您需要运行以下 docker 命令:

    docker run --name azure-cosmosdb-emulator --memory 2GB --mount "type=bind,source=%LOCALAPPDATA%\CosmosDBEmulator\bind-mount,destination=C:\CosmosDB.Emulator\bind-mount" --interactive --tty -e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true -p 8081:8081 -p 8900:8900 -p 8901:8901 -p 8902:8902 -p 10250:10250 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -p 10255:10255 -p 10256:10256 -p 10350:10350 mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator
    

    重要的变化是增加了:-e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true


    更新:

    我发现这会启用 3.2 协议,对于 3.6 协议,您需要使用:-e AZURE_COSMOS_EMULATOR_MONGODB_COMPUTE_ENDPOINT=true

    github discussion 中提供了更多讨论,其中有人还指出 Gremlin 和 Casandra 选项是:

    • -e AZURE_COSMOS_EMULATOR_GREMLIN_ENDPOINT=true
    • -e AZURE_COSMOS_EMULATOR_CASSANDRA_ENDPOINT=true

    【讨论】:

    • 我正在尝试像docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -p 10255:10255 -m 3g --cpus=2.0 --namtest-linux-emulator -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1 -e AZURE_COSMOS_EMULATOR_MONGODB_ENDPOINT=true -e AZURE_COSMOS_EMULATOR_MONGODB_COMPUTE_ENDPOINT=true -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator 一样在Mac 中运行模拟器,以通过mongo API 访问cosmos 模拟器。但它不起作用。任何帮助
    • 你使用的是什么连接字符串?
    • 似乎是 cosmos linux 模拟器的限制,不支持 Mongo API。
    猜你喜欢
    • 2019-03-30
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多