Node js os.networkInterfaces () returns no results when called through docker entry point on AWS

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

Inside node.js, one of the first things it does is look up the IP via

var ifaces = os.networkInterfaces();

      

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

  • AWS + Docker + manualstart node = YES!
  • AWS + Docker + autorun nodemon = YES
  • AWS + Docker + autostart node = NO

like 1 and 3 use the same simple commands, i think docker runs it before the network is started. This way, either I can run the init script start the network early or poll until something comes up. Does anyone know that the linux command to start the network sets the ip?

+3


source to share


1 answer


I chose to just setInterval until os.networkInterfaces returns null, it will change in time from 100ms to 500ms or so on the slower AWS instance.



+1


source







All Articles