Find IP address of Docker container
Adam K Dean
Posted on May 28, 2014
To get the IP address of a Docker container, use the following command:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID}
So let's say the ID of the container is a2150s
, we could get the IP like so:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' a2150s
172.17.0.2
I have written a script for this, /usr/local/bin/dockerip
:
#!/bin/bash
COUNT=`docker ps | grep $1 | wc -l | bc`
if [ $COUNT -gt 0 ]; then
IP_ADDRESS=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1`
echo "$1: $IP_ADDRESS"
else
echo "Could not find $1. Check container is running."
fi
This will form part of a repository of useful docker scripts.
π πͺ π
π©
Adam K Dean
Posted on May 28, 2014
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.