Created
January 23, 2015 15:07
-
-
Save diefans/cc9932c6a066877ccee1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # provide semi-automatic dns to docker container | |
| # just call this script | |
| DNSMASQ_CONF_DIR=/etc/dnsmasq.d | |
| PRIMARY_DOMAIN=ms.foo | |
| # get all containers | |
| CONTAINER_IDS=$(docker ps | tail -n +2 | awk '{ print $1}') | |
| function get_name { | |
| id=$1 | |
| docker inspect $id | jq ".[0].Name" | tr -d '/"' | |
| } | |
| function get_ip { | |
| name=$1 | |
| docker inspect $name | jq ".[0].NetworkSettings.IPAddress" | tr -d '"' | |
| } | |
| # get container names | |
| CONTAINER_NAMES=$(for id in $CONTAINER_IDS; do get_name $id; done) | |
| # create dnsmasq entries | |
| for id in $CONTAINER_IDS; do | |
| name=$(get_name $id) | |
| ip=$(get_ip $id) | |
| # create file | |
| echo "host-record=$name.$PRIMARY_DOMAIN,$ip" > $DNSMASQ_CONF_DIR/docker-$name.conf | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment