Created
March 1, 2017 20:57
-
-
Save brennancheung/62d2abe16569e600d2be5e9495c85331 to your computer and use it in GitHub Desktop.
look up the IPs of the containers for a Docker service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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