Last active
August 29, 2015 13:56
-
-
Save sdbondi/8951499 to your computer and use it in GitHub Desktop.
Create environment variables for docker containers on the host machine
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 | |
# Create environment variables for docker containers on the host machine | |
containers=( | |
"DB0:postgres" | |
"ES0:elasticsearch" | |
"REDIS0:redis" | |
) | |
for c in "${containers[@]}"; do | |
ALIAS="${c%%:*}" | |
CONTAINER="${c##*:}" | |
ip=$(docker inspect -format='{{ .NetworkSettings.IPAddress }}' $CONTAINER) | |
# Only gets first exposed port for now | |
port=($(docker inspect -format='{{ .NetworkSettings.Ports }}' $CONTAINER | sed "s/^map\[\([0-9]*\)\/\([a-z]\{3,\}\).*\]/\1 \2/")) | |
export "${ALIAS}_PORT_${port[0]}_${port[1]^^}"=${port[1]}://$ip:${port[0]} | |
export "${ALIAS}_PORT_${port[0]}_${port[1]^^}_PROTO"=$ip:${port[0]} | |
export "${ALIAS}_PORT_${port[0]}_${port[1]^^}_ADDR"=$ip | |
export "${ALIAS}_PORT_${port[0]}_${port[1]^^}_PORT"=${port[0]} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment