How to get the ip-address from your raspberry when using node-red and rhasspy in docker-containers

I’m making a simple node-red flow which reacts to the intent “WhatsMyIp”.
I used an exec-node in node-red to execute the following bash-command:
sbin/ip -4 -o addr show dev eth0| /usr/bin/awk ‘{split($4,a,"/");print a[1]}’

This “works” but it gives the ip-address “in the container” and that of course is not the one I need, it’s the ip-address of the raspberry in my home network I want.

I posted this also on the node-red forum but, there they suggested to not use docker, which seems a drastic measure for this problem.

Her is my node-red flow:
[{"id":"aa7ebe61.f0a9f","type":"tab","label":"WhatsMyIp","disabled":false,"info":""},{"id":"507071fb.dfcf78","type":"debug","z":"aa7ebe61.f0a9f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":100,"wires":[]},{"id":"4c8ca89e.31f138","type":"exec","z":"aa7ebe61.f0a9f","command":"/sbin/ip -4 -o addr show dev eth0| /usr/bin/awk '{split($4,a,\"/\");print a[1]}'","addpay":false,"append":"","useSpawn":"false","timer":"20","oldrc":false,"name":"GetIp","x":310,"y":160,"wires":[["507071fb.dfcf78"],[],[]]},{"id":"db06641a.216ec8","type":"inject","z":"aa7ebe61.f0a9f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":260,"wires":[["4c8ca89e.31f138"]]}]

any idea for a better solution?

kind regards,
hugo

I think their response is generally right: I don’t see any way to get the IP address of the host system from within the container when you’re using Docker’s network.

However, that changes when you’re using the host network in your container. Then it should be possible to get the IP address of your host’s network interface. Note that the container’s network stack is then not isolated anymore from the host, which increases the attack surface.

1 Like

What I can think of right now is to write the ip into a file on the hostsystem, use a cronjob or something to keep it current in case it changes (I would suggest a static ip if it does, dynamic ips for servers aren’t that great), add that as a mount to the docker container and read the ip with node-red.

What you also could try is to ping the host pi from the docker container using the hostname, but I am not sure if that will work. My docker containers all run on the host network because one container can’t access one feature without that and I didn’t fancy figuring out how to get containers outside the host network to communicate with containers within.

1 Like

Google is your best friend :wink: