This package consists of a couple of utilities to get IP addresses of containers and host from inside a docker container.
Install this package
using yarn:
yarn add docker-ip-get
or using npm:
npm install docker-ip-get
Here is an example usage:
First, import the library
in CommonJS format:
const dockerIpTools = require("docker-ip-get");
or in ES6 format:
import * as dockerIpTools from "docker-ip-get";
Then, use the utilities as follows:
// Get IP address of the docker host
dockerIpTools
.getHostIp()
.then((hostIp) => console.log(hostIp))
.catch((err) => console.error(err));
// Get IP address of the docker container this script is running in
dockerIpTools
.getContainerIp()
.then((containerIp) => console.log(containerIp))
.catch((err) => console.error(err));
// Get IP address of the docker gateway
dockerIpTools
.getGatewayIp()
.then((hostIp) => console.log(hostIp))
.catch((err) => console.error(err));
// Check if the system is a docker container
dockerIpTools.isInDocker();
If you encounter any issues, please feel free to post an issue here.
Any Pull Requests are welcome!!
This project was inspired by docker-ip and this stackoverflow post.
docker-ip-get
is MIT Licensed.