Created
August 15, 2017 13:08
-
-
Save johanvanhelden/0a9670598fe6ab96c9af7c38c9bcf26a to your computer and use it in GitHub Desktop.
Create dockerhero hosts section
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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