Skip to content

Instantly share code, notes, and snippets.

@pollosp
Created April 18, 2016 18:23
Show Gist options
  • Save pollosp/54015741eac50612ebf249f0f2a5d476 to your computer and use it in GitHub Desktop.
Save pollosp/54015741eac50612ebf249f0f2a5d476 to your computer and use it in GitHub Desktop.
Consul and consul-template
https://hub.docker.com/_/ruby/
progrium/consul
gliderlabs/registrator
HOW TO
SET IP
DOCKER_IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | grep -v 10.)
RUN consul server
docker run -d -d -h dev -p 8300:8300 -p 8301:8301 -p 8301:8301/udp -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 53:53 -p 53:53/udp progrium/consul -server -advertise $DOCKER_IP -bootstrap-expect 1
RUN REGISTRATOR
docker run -t -v /var/run/docker.sock:/tmp/docker.sock gliderlabs/registrator -ip $DOCKER_IP consul://$DOCKER_IP:8500 -bootstrap
RUN RACK
docker run --dns 172.17.0.2 -e SERVICE_NAME=rack1 -e SERVICE_TAGS=www -e PORT=83 -p 83:83 -d rack
RUN HAPROXY
docker run -e CONSUL_HTTP_ADDR=162.243.206.218:8500 -e SERVICE_NAME=www --dns 172.17.0.2 -p 8000:8000 -ti 56a68a919f51
DOCKER FILES
RACK
FROM ruby
ENV PORT 8080
run curl https://gist.githubusercontent.com/pollosp/1ebd781f01e95b33e869/raw/9c65fdc75509d4d1d54617b19cb7d15d5a8961ea/dockerfile -o /mnt/rackup.sh
run chmod +x /mnt/rackup.sh
ENTRYPOINT /mnt/rackup.sh
HAPROXY
FROM alpine
MAINTAINER Ilkka Anttonen version: 0.3
RUN apk --update add haproxy wget unzip curl
RUN ( wget --no-check-certificate https://releases.hashicorp.com/consul-template/0.12.2/consul-template_0.12.2_linux_amd64.zip -O /tmp/consul_template.zip && cd /tmp && unzip consul_template.zip && mv consul-template /usr/bin && rm -rf /tmp/* )
COPY haproxy.json /tmp/haproxy.json
COPY haproxy.ctmpl /tmp/haproxy.ctmpl
CMD ["consul-template", "-config=/tmp/haproxy.json"]
OTHER REQUIRED FILES
haproxy.json
template {
source = "/tmp/haproxy.ctmpl"
destination = "/etc/haproxy/haproxy.cfg"
command = "haproxy -f /etc/haproxy/haproxy.cfg -sf $(pidof haproxy) &"
}
haproxy.ctmpl
global
daemon
defaults
mode http
timeout connect 5000
timeout client 50000
timeout server 50000
option http-server-close
balance roundrobin
frontend http
bind :8000
default_backend app_pool
backend app_pool
{{range $c,$d:=service "rack1"}}
server {{.Node}}-{{$c}} {{.Address}}:{{.Port}} check
{{end}}
HELPERS
docker images
docker ps
docker kill
curl localhost:8500/v1/catalog/service/rack1
docker exec -it [container-id] bash
docker inspect <container id>
THINGS TO TRY
⁃ https://github.com/containous/traefik
⁃ https://github.com/WeAreFarmGeek/diplomat
Resources
⁃ http://www.maori.geek.nz/scalable_architecture_dr_con_docker_registrator_consul_nginx/
⁃ http://sirile.github.io/2015/05/18/using-haproxy-and-consul-for-dynamic-service-discovery-on-docker.html#running-the-haproxy
⁃ http://sirile.github.io/2015/05/18/using-haproxy-and-consul-for-dynamic-service-discovery-on-docker.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment