Find Windows Container IP Address Running On Docker

In this blog post, I’ll show you how to check a Windows Server Container IP address using two methods.

Finding a Container IP address Is something that Is always needed when troubleshooting containers or when operating them In production.

This post will show you two methods to achieve this goal.

Get started

To get started, I’ll create a Windows Server Container running Windows Server Core 2016 which I use for example In this post.

Both methods will work on Linux Containers or Windows Containers as well on hosts.

docker run -d -it --name demo microsoft/windowsservercore

Docker Inspect

In the first method below, I’m using the Docker Inspect command (command Is case sensitive).

The return output Is very specific and the IP address Is returned without any additional data.

docker container inspect --format '{{.NetworkSettings.Networks.nat.IPAddress }}' demo

Docker Exec

In the second method below, I’m using Docker Exec to run the Ipconfig command on my Windows Server.

This method return a lot of Information the I probably don’t need and to run this the Container needs to In running state.

docker exec demo powershell.exe ipconfig

Conclusion

My prefered method to get IP Information from a running Container Is using docker Inspect however the command Is a bit long.


Posted

in

by