Tip of the day: Host IP inside Docker container

Hi there

After googling for hours, I made my own solution for the "get the Host IP adress"

I am using this Stack for my IOT setup: IOTstack

I want to post the Host ip to a grafana desktop.
This is how I did it:

first switch to root sudo su
then in crontab -e
add lines:
*/5 * * * * hostname -I>"/home/pi/IOTstack/volumes/nodered/data/ip.txt" this will write the IP adress to the ip.txt file every 5 minutes (for testing)
@reboot hostname -I>"/home/pi/IOTstack/volumes/nodered/data/ip.txt"

In Node red I made this flow:

[{"id":"52156a8f.946d34","type":"file in","z":"e08d24f1.370bf8","name":"","filename":"/data/ip.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":350,"y":180,"wires":[["b2c1fb19.46e6b8"]]},{"id":"b2c1fb19.46e6b8","type":"function","z":"e08d24f1.370bf8","name":"","func":"var IPaddress = msg.payload.split(\" \")[0];\n\nmsg.payload = {\n IPaddress: IPaddress,\n \n }\n node.status({fill:\"green\",shape:\"ring\",text:IPaddress});\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":180,"wires":[["3e080cf4.025294","16496085.a079bf"]]},{"id":"e378696d.401a38","type":"inject","z":"e08d24f1.370bf8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":180,"wires":[["52156a8f.946d34"]]}]

Best regards
Henrik