handy bash script to get docker container's IP

Since docker inspect command displays lots of information, I created this script to get docker container's IP by passing either its CONTAINER_ID or its NAME.

If no parameter is given, it will just output the IP of docker0 interface.



if [[ -n "$docker_container_name" ]]; then  
  docker inspect $docker_container_name | grep '"IPAddress' | cut -d '"' -f4 | awk '{print $1}' | uniq
  ifconfig docker0 | grep "inet addr" | cut -d: -f2 | awk '{print $1}'

I usually name it dip with no extension and put it on my servers in /usr/local/bin. If you decide to place it there as well, remember to change owner, group and permission:

sudo chown root:root /usr/local/bin/dip  
sudo chmod 755 /usr/local/bin/dip  

Here's the gist for this script.