Skip to content

Instantly share code, notes, and snippets.

@johanvanhelden
Created August 15, 2017 13:08
Show Gist options
  • Save johanvanhelden/0a9670598fe6ab96c9af7c38c9bcf26a to your computer and use it in GitHub Desktop.
Save johanvanhelden/0a9670598fe6ab96c9af7c38c9bcf26a to your computer and use it in GitHub Desktop.
Create dockerhero hosts section
#!/bin/bash
#get all containers
containers=`docker ps -a --format '{{.Names}}'`
hostFileBegin="## DOCKERHERO HOSTS BLOCK START ##\n"
hostFileEnd="## DOCKERHERO HOSTS BLOCK END ##\n"
hostFile=$hostFileBegin
#find the ip belonging to container
for containerName in ${containers[@]}
do
containerIP=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $containerName`
hostFile+="$containerIP $containerName\n"
done
hostFile+=$hostFileEnd
echo -e $hostFile
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment