Get Docker container IP within a .net core application

Ok, I got it working and it was much easier than I thought.

var name = Dns.GetHostName(); // get container id
var ip = Dns.GetHostEntry(name).AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);

With the container_id/name I could get the IP with an easy compare if it's an IP4 address. I then can use this address and pass it to Consul. The health checks can now successfully call the container with it's IP from the outside host.

I'm still not 100% satisfied with the result because it relies on the "first" valid IP4 address in the AddressList (currently, there are no more so I got this going for me). Any better / more generic solution would still be welcome.