Robert Cemper · Mar 15

? how to get Docker Host IP ?

When I run my IRIS in a Docker Container I know the host an know the mapped ports
so access is no problem.

BUT: is it possible from my IRIS
- inside a Container
- 'inside' Docker
to find the actual IP address of the Host?

This may sound strange, but for error tracking, it could be quite important.

Product version: IRIS 2022.2
0 173
Discussion (9)2
Log in or sign up to continue

Hi @Robert Cemper ,

I already do this with an environment variable passed in the docker-compose file.  I don't know if smarter solution exists. 

From a container running in docker, you can always reference host.docker.internal which resolves to the hostname of your host.  If you need an external IP address of the host, then you'll need to do something to pass in the ipaddress to the container

Thanks you for this tips @Bob Kuszewski 

Maybe the following line allows to retrieve, but I don't have Windows Docker environment to test myself:

Set ip = $SYSTEM.INetInfo.HostNameToAddr("host.docker.internal")

@Robert Cemper : If you test this line with Docker for Windows, let me know if It works or not.

Thank you.

I did the test, but it failed.

C:\GitHub\_my\SSH-for-IRIS-container>docker-compose exec iris iris session iris

Node: f386a88482f2, Instance: IRIS
USER>Set ip = $SYSTEM.INetInfo.HostNameToAddr("host.docker.internal")
USER>zw ip

The correct IP =
it's also not the IP-Address of WSL-2 shell
It's not even in the DHCP range of my router, nor in the WLAN range

BUT: this is an excellent use case for my recent Proposal

Not sure why you think, that the IP is wrong. And probably it's the Windows thing and WSL

But, I use this way a lot of time, when I need to access from some docker container, some another service running locally, or another docker container not connected to the same network, and it works fine. This address is supposed to be used only from the container, it should not show the real IP address of the host. If you wish to show some URL, which will be available outside of the container, obviously it will not help.

You are correct it is working inside docker in the container.
But I asked for the external real IP of my (Windows) Host.
I know that is wrong for my purpose,  as I sit just in front of it
and use it some 100 times daily. So I really know it.

It's an odd situation: IRIS -> Ubuntu in container -> Docker -> WSL -> Windows.
I didn't add NAT and Port mapping used by Windows. 


I'm not sure if this helps your particular situation, but if it's "OK" to manually tell your container what the local hostname of the host is, then you could try this:

set ip=$SYSTEM.INetInfo.HostNameToAddr("**local_name_NotFQDN**")

with just the local hostname (not the FQDN) of the host machine in quotes... and that should give you the IP address of the active ethernet/wireless adapter. I tried this in a container running IRIS on a Raspberry Pi and the local hostname is "Iris2" (so, it is running Linux, I don't have any container systems running on Windows... sorry!) and this is what I got:

USER> Set ip=$SYSTEM.InetInfo.HostNameToAddr("Iris2")
USER> zw ip

On my network, 172.17.0.x is the internal Docker bridge, 192.168.1.x is my wireless network, and 10.1.2.x is my desktop wired network. (I have many servers, printers & whatnot, so I have multiple VLANs on my home network.) Now... I'm not sure if this is good or bad for your situation, but in my example, if I were to shutdown the container, disable the wireless, hook up an ethernet cable to the network and restart everything, the listed IP from this command would change from the 192.168.1.x to a 10.1.2.x IP address. This could be good if you wanted to know how the main machine was externally connected; or it could be bad if you're using awk/grep/findstr on logs looking for a particular IP. As I said, I'm unsure of your actual use case, so if this had to be portable across several containers and several machines unchanged, this may not help you as you'll manually have to change the machine name in your code.

Hope this helps!

I use this tidbit to get an external ip

curl -s

If you want the docker-host ip and not the external ip, I use host networking and then use

hostname -I