Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986 Lewiscowles1986/README.md
Last active Nov 24, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.