如何使用C#中的Docker.dotnet库连接到远程Docker守护进程?

时间:2018-12-06 09:39:38

标签: c# docker remote-access

我是Docker的新手,我当前的项目需要连接到远程Docker守护程序。我正在dotnet框架中进行开发,并使用docker.dotnet库。我必须连接到网络中的远程docker守护程序,这是我发现的代码:

DockerClient client = new DockerClientConfiguration(
        new Uri("http://192.168.64.183:2375"))
        .CreateClient();

我可以通过将当前的Uri字段替换为'http://127.0.0.1:2375'或'localhost:2375'来正常工作。

但是,这就是我尝试连接远程docker守护程序时得到的,

"Message": "An error has occurred.",
    "ExceptionMessage": "Connection failed",
    "ExceptionType": "System.Net.Http.HttpRequestException",
    "StackTrace": "   at Microsoft.Net.Http.Client.ManagedHandler.<P
.............................something here...............
"InnerException": {
        "Message": "An error has occurred.",
        "ExceptionMessage": "No connection could be made because the target machine actively refused it [::ffff:192.168.64.183]:2375",
        "ExceptionType": "System.Net.Sockets.SocketException",
        "StackTrace": "   at Microsoft.Net.Http.Client.ManagedHandler.<TCPSocketOpenerAsync>d__37.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Net.Http.Client.ManagedHandler.<ProcessRequestAsync>d__33.MoveNext()"

先谢谢了。

0 个答案:

没有答案