我无法使用在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
mongodb://localhost:C2y6yDjf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true
我能够在https://localhost:8081/_explorer/index.html上访问资源管理器,因此模拟器正在运行。
我在应用程序中使用猫鼬
答案 0 :(得分: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