Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Last active November 24, 2018 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lewiscowles1986/2c80f1e510152b461eae5c501a00a195 to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/2c80f1e510152b461eae5c501a00a195 to your computer and use it in GitHub Desktop.
Get IP of running docker container

Get docker container IP address by name

Installation

mkdir -p $HOME/bin
wget -O ~/bin/docker-container-ip https://gist.github.com/Lewiscowles1986/2c80f1e510152b461eae5c501a00a195/raw/6b60245035ee63a025db20e287f89d74db08b356/docker-network-ip
chmod +x ~/bin/docker-container-ip

Troubleshooting: You may additionally need to run the following command to ensure the script is available in your path. Additionally you need write-permissions for your $HOME folder

export PATH=$PATH:$HOME/bin

Usage

docker-container-ip {container-name}
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Must provide a name"
exit 1
fi
#
# uses https://stackoverflow.com/a/20686101/1548557
#
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment