首页 文章

MongoDB atlas连接无法在运行ASP.net核心的docker容器中运行 . 从红隼内部工作得很好

提问于
浏览
0

我们有基于asp.net核心的docker容器尝试使用C#驱动程序版本2.4.3连接到MongoDB atlas .

当我们在容器外运行连接时,连接正常 . 即直接来自红隼 . 但是当从容器内运行相同的代码时,与mongodb atlas的连接会超时 .

Details: MongoDB C#驱动程序版本:2.4.3

连接字符串:mongodb:// sa:@ cluster0-shard-00-00-po5vp.mongodb.net:27017,cluster0-shard-00-01-po5vp.mongodb.net:27017,cluster0-shard-00-02- po5vp.mongodb.net:27017/admin?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin

要访问的数据库:配置

ASP.net核心版:1.1

Dockerfile中的BaseImage:microsoft / aspnetcore-build

Dockerfile内容:FROM microsoft / aspnetcore-build WORKDIR / SaaS_Configuration_Microservice COPY ./SaaS_Configuration_Microservice . EXPOSE 80 RUN dotnet恢复RUN dotnet发布-c Release -o PublishOutput ENTRYPOINT [“dotnet”,“PublishOutput / SaaS_Configuration_Microservice.dll”]

我们在Windows 10中运行红隼 .

Complete Error Message: ex.Message "A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = }, LatencyLimitingServerSelector }. Client view of cluster state is { ClusterId : " 1 \ ", ConnectionMode : " ReplicaSet \ ", Type : " ReplicaSet \ ", State : "断开\ ", Servers : [{ ServerId: " {丛集编号:1, endpoints :\ "Unspecified/cluster0-shard-00-00-po5vp.mongodb.net:27017"} \ ", EndPoint: "未指定/ cluster0-shard-00-00-po5vp.mongodb.net:27017 \ ", State: "断开\ ", Type: " Unknown \ ", HeartbeatException: " MongoDB.Driver.MongoConnectionException:打开与服务器的连接时发生异常 . ---> MongoDB.Driver.MongoCommandException:命令失败 . \ n在MongoDB.Driver.Core.WireProtocol.CommandWireProtocol 1.ProcessReply(ConnectionId connectionId, ReplyMessage 1回复)\ n在MongoDB.Driver.Core.WireProtocol.CommandWireProtocol 1.<ExecuteAsync>d__11.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.ConnectionInitializer.<InitializeConnectionAsync>d__3.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()\n --- End of inner exception stack trace ---\n at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\n at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__27.MoveNext()\" }, { ServerId: \"{ ClusterId : 1, EndPoint : \"Unspecified/cluster0-shard-00-01-po5vp.mongodb.net:27017\" }\", EndPoint: \"Unspecified/cluster0-shard-00-01-po5vp.mongodb.net:27017\", State: \"Disconnected\", Type: \"Unknown\", HeartbeatException: \"MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoCommandException: Command failed.\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol 1.ProcessReply(ConnectionId connectionId,ReplyMessage 1 reply)\n at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol 1.d__11.MoveNext()\ n ---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices上的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ n中的\ n . MongoDB.Driver.Core.Connections.ConnectionInitializer.d__3.MoveNext()中的TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ n \ n \ n \ n ---从抛出异常的上一个位置开始的堆栈跟踪结束--- \ n在System.Runtime .ExceptionServices.ExceptionDispatchInfo.Throw()\ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ n在MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\ n ---内部结束异常堆栈跟踪--- \ 在MongoDB.Driver.Core.Conn ections.BinaryConnection.d__48.MoveNext()\ n ---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices上的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ n中的\ n .TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ n在MongoDB.Driver.Core.Servers.ServerMonitor.d__27.MoveNext()\ " }, { ServerId: " {ClusterId:1,EndPoint:\ "Unspecified/cluster0-shard-00-02-po5vp.mongodb.net:27017"} \ ", EndPoint: "未指定/ cluster0-shard-00-02- po5vp.mongodb.net:27017 \ ", State: "已断开连接 ", Type: "未知\ ", HeartbeatException: " MongoDB.Driver.MongoConnectionException:打开与服务器的连接时发生异常 . ---> MongoDB.Driver.MongoCommandException:命令失败 . \ n在MongoDB.Driver.Core.WireProtocol.CommandWireProtocol 1.ProcessReply(ConnectionId connectionId, ReplyMessage 1回复)\ n在MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.d__11.MoveNext() n ---从抛出异常的先前位置开始的堆栈跟踪结束---在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ n的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ n中的\ n在MongoDB.Driver.Core.Connections.ConnectionInitializer.d__3.MoveNext()\ n ---从抛出异常的上一个位置开始的堆栈跟踪结束--- \ n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ n在MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\ n ---内部异常堆栈跟踪结束--- \ n at MongoDB.Driver.Core.Connections.BinaryConnection.d__48.MoveNext()\ n ---来自prev的堆栈跟踪结束抛出异常的位置--- \ n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ n处于System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ n,位于MongoDB.Driver.Core.Servers . ServerMonitor.d__27.MoveNext()\ _ _ 11151585 string

内部异常:空值

1 回答

  • 1

    "microsoft/aspnetcore-build"是一个Linux映像,有一个错误:https://docs.atlas.mongodb.com/driver-connection/#c-net-driver-example

    重要事项.NET Core库不支持Linux和OSX上的SNI TLS扩展 . 在这些操作系统上使用.NET Core的应用程序无法连接到Atlas Free Tier集群 . 在dotnet / corefx github页面上跟踪该问题 .

相关问题