How to use ip in docker container

5/7/2019

How to create public container image if I am declaring ip address for mongo db in my nodejs app like:

const client = mongoose.connect("mongodb://192.168.99.100:27017/db", ...
  1. Do I need to use library like public-ip to get the address:
const publicIp = require('public-ip');

(async () => {
    console.log(await publicIp.v4());
    //=> '46.5.21.123'

    console.log(await publicIp.v6());
    //=> 'fe80::200:f8ff:fe21:67cf'
})();
  1. Do I have to know from top which addresses container will use?

  2. Or there is some approach any convention like i.e if containers run on one pod they share same internal local address 127.0.0.1?

-- Konrad Grzyb
docker
kubernetes
minikube
mongodb
node.js

1 Answer

5/7/2019

You should look at Kubernetes Services. Pod and the containers inside them are meant to be ephemeral. As mentioned in the link:

While each Pod gets its own IP address, even those IP addresses cannot be relied upon to be stable over time.

On the other hand, Services have stable IP address. They also allow discovery using environment variables and DNS as specified in the same link.

-- Alassane Ndiaye
Source: StackOverflow