简体   繁体   中英

Docker.Dotnet :: Trying to enlist all the nodes in a Swarm

I've been trying to enlist all nodes in my docker swarm but it throws a weird type conversion error.

Here's what I've tried so far:

  1. Connected to Docker using DockerClient object (using Docker.DotNet NuGet package)
  2. Made a separate thread to get the response from the Async Function (LoadNodesAsync).
  3. Tried to traverse through the response using an enumerator.

Here's the complete code:

static void Main(string[] args){
    while (true)
    {
        GetNodesList();
        Thread.Sleep(5000);
    }
}

async static private void GetNodesList(){
    try
    {
        DockerClient Client = new DockerClientConfiguration(
            new Uri("npipe://./pipe/docker_engine"))
            .CreateClient();

        CancellationTokenSource cancelSource = new CancellationTokenSource();

        var result = await Client.Swarm.ListNodesAsync(cancelSource.Token);
        var enumerator = result.GetEnumerator();
        Console.WriteLine(enumerator.Current.ID.ToString());

        cancelSource.Cancel();

    }
    catch (Exception ex)
    {

    }
}

It throws an exception inside GetNodesList function where the following line is written:

var result = await Client.Swarm.ListNodesAsync(cancelSource.Token);

Exception:

Error converting value "MBMxETAPBgNVBAMTCHN3YXJtLWNh" to type 'System.Collections.Generic.IList 1[System.Byte]'. Path '[0].Description.TLSInfo.CertIssuerSubject', line 1, position 1608.

The result objects contain Not Yet Computed .

What am I doing wrong?

Turns out my approach was fine. The issue was caused by a bug in Docker.DotNet library's version 3.125.4 . The issue can be resolved by using the previous version of the library , ie: version 3.125.2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM