Search

Wednesday, August 10, 2016

Grab Basic Network Info from Docker Container

Learning Docker has forced me to learn more about basic Linux tools. One such tool is GREP, or Global Regular Expression Print.

GREP is quite a powerful, yet simple tool for searching text. Docker has lots of text that can be searched when using Docker commands such as docker inspect. Using this command can return a lot of text on your screen. While this can be useful, why hurt your eyes looking for simple network information on a particular container? Enter GREP.

In this example, I'm looking for just the name of the container, it's IP address(es) and MAC address(es). 


 docker network inspect 4136d04999bc | grep 'Name\|IPv4Address\|MacAddress'  

As you can see, I use the command docker network inspect [containerID] and pipe that text to the GREP utility which allows me to search for the regular expression. 

You should see something similar to the following:


docker network inspect + GREP







The above is plain text but since you can do so much with regular expressions, there isn't much you can't find using this example as a starting point.

For more information on using GREP and regular expressions as well as Docker networking, visit the following sites:

Grep - An introduction to grep and egrep. How to search for strings inside of files.

Docker - Work with network commands