node js os.networkInterfaces() not returning any results when called through docker entrypoint on AWS

472 views Asked by At

I have node.js running inside a docker container. When I start docker, it then calls a script that calls node.js (or nodemon) to start.

Inside that node.js one of the first things it does is look for it's IP via

var ifaces = os.networkInterfaces();

But it doens't work all the time, for reasons that mystify me:

  1. AWS+Docker+manualstart node = YES!
  2. AWS+Docker+autostart nodemon= YES
  3. AWS+Docker+autostart node = NO

as 1, and 3 use identical plain commands my best guess is that docker is starting it before the network has been started. So either I can have the init script start the network earlier or poll until something shows up. Does anybody know the linux command to start the network set the ip?

1

There are 1 answers

0
TroyWorks On

I opted to just setInterval till the os.networkInterfaces returned a non-null value, it varies in time from 100ms to 500ms or so on a slower AWS micro instance.