10 Examples of how to get Docker Container IP Address

10 Examples of how to get Docker Container IP Address

Docker Turtles Banner Network Copy

10 Examples of how to get Docker Container IP Address

One thing that is so much fun about the need virtualization paradigm we are heading towards is that in the age of “software defined”, the flexibility of how to do things with infra are much more like programming then working with highly opinionated traditional infrastructure. Along that thread, here are 10 different ways to get a container or docker-machine address using the Docker/Docker-Machine CLI. This doesn’t even go into the remote http API which is slick because the client commands below are actually making calls to the verioned API described here.

Much of the motivation to show so many different ways is to help folks see the flexibility that I still run into nearly daily which is hard not to excite a hacker. They can also be viewed in this Gist.

Bonus Example! 🙂
If you have a user defined network as opposed to the default network, simply grepping on docker inspect is a quick way to parse any field.

Lets say you created a Macvlan network to use the same network as the Docker host eth0 interface. In this case eth0 on the Linux host is the following:

Create a network that will share the eth0 interface:

Now grep details about the container:

You can just as easily look at the details of the network:

Lastly, take a look at the docker network inspect details to view the metadata of the network mcv1 you created:

Thats all for now. There are likely plenty of other ways but this should be enough to tackle most automation scenarios. I am wanting to keep most of the current blogging geared towards Docker novices for the next little bit until most in networking are up to speed and then we will go deep. Lots more to come! To my network hacking friends, I will be digging into some lower level Linux netlink and interfacing with that with Go funs next weekend so stay tuned!

New Ipvlan and Macvlan Drivers

Thanks for stopping by!

About the Author

Brent SalisburyI have over 15 years of experience wearing various hats from, network engineer, architect, devops and software engineer. I currently have the pleasure of working at the company that develops my favorite software I have ever used, Docker. My comments here are my personal thoughts and opinions. More at Brent's BioView all posts by Brent Salisbury →