Created
February 5, 2019 10:18
-
-
Save earnubs/f615de2586cb0e4b6b28b2c296a18dce to your computer and use it in GitHub Desktop.
use dockerode to get container ip address
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 Docker = require('dockerode'); | |
const fs = require('fs'); | |
const socket = process.env.DOCKER_SOCKET || '/var/run/docker.sock'; | |
const stats = fs.statSync(socket); | |
if (!stats.isSocket()) { | |
throw new Error('Are you sure the docker is running?'); | |
} | |
const docker = new Docker({ socketPath: socket }); | |
module.exports.getFrontendIP = function() { | |
return new Promise((resolve, reject) => { | |
docker.listContainers({}, (err, containers) => { | |
if (err) reject(err); | |
const container = containers.find( | |
node => node.Image === 'toolchain-web_frontend', | |
); | |
resolve( | |
container.NetworkSettings.Networks['toolchain-web_default'].IPAddress, | |
); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment