# Tip of the day: Host IP inside Docker container

**URL:** <https://discourse.nodered.org/t/tip-of-the-day-host-ip-inside-docker-container/45180>\
**Category:** General\
**Created:** [4 May 2021 19:55 UTC](https://discourse.nodered.org/t/tip-of-the-day-host-ip-inside-docker-container/45180 "2021-05-04T19:55:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rothestar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rothestar/32/30672_2.png) [@rothestar](https://discourse.nodered.org/u/rothestar)\
**Post date:** [4 May 2021 19:55 UTC](https://discourse.nodered.org/t/tip-of-the-day-host-ip-inside-docker-container/45180/1 "2021-05-04T19:55:31Z")

</div>

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](https://sensorsiot.github.io/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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 July 2021 19:55 UTC](https://discourse.nodered.org/t/tip-of-the-day-host-ip-inside-docker-container/45180/2 "2021-07-03T19:55:40Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
