Skip to content

Instantly share code, notes, and snippets.

@brennancheung
Created March 1, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennancheung/62d2abe16569e600d2be5e9495c85331 to your computer and use it in GitHub Desktop.
Save brennancheung/62d2abe16569e600d2be5e9495c85331 to your computer and use it in GitHub Desktop.
look up the IPs of the containers for a Docker service
const dns = require('dns')
function lookup (serviceName) {
const tasks = `tasks.${serviceName}`
return new Promise((resolve, reject) => {
dns.lookup(tasks, { all: true }, (err, addresses, family) => {
if (err) {
return reject(err)
}
const filtered = addresses.filter(address => address.family === 4)
const ips = filtered.map(x => x.address)
resolve(ips)
})
})
}
async function main () {
const result = await lookup('hello')
console.log(result)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment