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:
- AWS+Docker+manualstart node = YES!
- AWS+Docker+autostart nodemon= YES
- 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?
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.