All docker Linux instances have a fixed IP address for the host (172.17.0.1). Balena engine seems to be no exception, with Raspberry Pi devices always coming up on that IP. Raspberry Pi 4:
br-17bf457e9f0b Link encap:Ethernet HWaddr 02:42:F4:17:D1:F7
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
I just started using an Intel NUC device with Balena OS, and this isn’t the behaviour. The IP address seems to change. This is usually only behaviour seen on Docker MacOS or Docker Windows. Any ideas what could be going on?
Hi @maggie0002, as far as I’m aware the 172.17.0.0 subnet is the default bridge network but it’s possible that balena-engine chooses a different one from a set of predefined subnets (see balena-libnetwork/utils.go at 20.10-balena · balena-os/balena-libnetwork · GitHub). I’m not sure under what circumstances this happens however, for example if you create additional bridge networks, or if there is a collision, but I’ll ask the engine team to see if they can provide insight.
That said, you shouldn’t assume 172.17.0.1 is always the host, even for specific device types. For example on my NUC it is 172.17.0.1, and I’ve certainly seen Pi’s with 172.18.x.x:
Thanks for sharing your experiences with it. I had considered the idea of awk or grep, but been trying to avoid it, it just felt a bit hacky. And considered a bunch of other things too, using unix sockets, moving everything to the host network, the list goes on. I guess in this instance, without any official Docker/Balena engine hostname that can be relied on like with Docker for Mac they are all a little bit hacky and the awk method probably most reliable.
I’m thinking the host IP address should be static once the device is online, so could run it on start of a container and store it in an env variable? Has that been your experience? Maybe via an entry point script? Would be helpful if you have anything you have already put together that works to base it off, rather than reinventing the wheel.
@tmigone here is a new one I haven’t seen before. On a Raspberry Pi 4 I was getting multiple IP addressed returned from ip route | awk '/br-/ { print $7 }'. When putting it in a env variable it ended up failing as it was trying to read a long list. I changed it instead to: