Last active
March 1, 2017 06:48
-
-
Save alexmherrmann/b65e28c31e75e402d6fd5b539e349422 to your computer and use it in GitHub Desktop.
Get the ip address of a docker container (with optional network argument)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ ! -z "$2" ]; then | |
command="docker inspect -f {{.NetworkSettings.Networks.$2.IPAddress}} $1" | |
# echo $command | |
result=`$command` | |
else | |
comand="docker inspect -f {{.NetworkSettings.IPAddress}} $1" | |
# echo $command | |
result=`$command` | |
fi | |
if [ "$result" == "<no value>" ]; then | |
echo "no value found, are you sure your network is correct? (use docker inspect -f {{.NetworkSettings}} to see what's up)" | |
elif [ ${#result} -lt 8 ]; then | |
echo "no ip found... (docker inspect -f {{.NetworkSettings}} may be useful)" | |
else | |
# echo ${#result} | |
echo $result | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified -f placement to make it more cross-version compatible (I think)