typescriptdockerdockerode

How can I use filters in listNetworks with dockerode?


I want to list docker networks with specific name and I've tried to use options like

import Docker from "dockerode";
const docker = new Docker();
const ntw =  await docker.listNetworks({
         Name:"qwerty"
  })
console.log(ntw);

But when I tried to run this script I got all networks so how can i get network with name "qwerty" only? Picture as follows.
enter image description here


Solution

  • Just use Array.prototype.filter

    import Docker from "dockerode";
    const docker = new Docker();
    const ntw =  await docker.listNetworks({
             Name:"qwerty"
      })
    const [qwerty] = ntw.filter(elem=>elem.Name==='qwerty')