Skip to content

Instantly share code, notes, and snippets.

@alexmherrmann
Last active March 1, 2017 06:48
Show Gist options
  • Save alexmherrmann/b65e28c31e75e402d6fd5b539e349422 to your computer and use it in GitHub Desktop.
Save alexmherrmann/b65e28c31e75e402d6fd5b539e349422 to your computer and use it in GitHub Desktop.
Get the ip address of a docker container (with optional network argument)
#!/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
@alexmherrmann
Copy link
Author

Modified -f placement to make it more cross-version compatible (I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment