Skip to content

Instantly share code, notes, and snippets.

@Markbnj
Created August 11, 2015 20:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Markbnj/779e8d4696c3f53b5ffb to your computer and use it in GitHub Desktop.
Save Markbnj/779e8d4696c3f53b5ffb to your computer and use it in GitHub Desktop.
Inject the ec2 instance private IP into a docker container at start
# Sometimes you need to get the IP of the ec2 instance a container
# is running on. This script will get the IP from the local metadata
# service and inject it as an environment var.
localip=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
export HOST_IP=$localip
sudo docker run -i -t -e "HOST_IP=$localip" --name="test" -h="test" some-repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment