Skip to content
Go to file
Cannot retrieve contributors at this time
74 lines (54 sloc) 1.89 KB


For all examples you need to run consul and registrator. Make sure you have boot2docker installed, so that you can run the examples below on your own machine.

Run consul:

$ docker run --name consul -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp -h node1 gliderlabs/consul-server -advertise -bootstrap

Run registrator:

$ docker run \
  --name registrator \
  -d \
  -v /var/run/docker.sock:/tmp/docker.sock \
  -h $HOSTNAME gliderlabs/registrator consul://


Run nginx container which will route requests to the hello-world container:

$ docker run --name nginx -d -p 80:80 -v /etc/nginx/sites-available nginx

Run consul template container which generates nginx configuration (modify the location of the nginx.ctml below):

$ docker run \
 --name nginx-consul-template \
 -d \
 -v /var/run/docker.sock:/tmp/docker.sock \
 -v /Users/albertvth/Development/github/docker-consul-template/examples/nginx.ctml:/tmp/nginx.ctmpl \
 --volumes-from nginx \
 avthart/consul-template \
 -consul= -wait=5s -template="/tmp/nginx.ctmpl:/etc/nginx/sites-available/default:docker kill -s HUP nginx"

Start a hello-world container:

$ docker run --name hello-world-1 -e SERVICE_NAME=hello-world -d -p 80 tutum/hello-world

Check if you can retrieve the hello-world page:

$ curl

When you stop the container you should get a HTTP 502.

Start another hello-world container:

$ docker run --name hello-world-2 -e SERVICE_NAME=hello-world -d -p 80 tutum/hello-world

This one should be automatically discovered by the nginx-consul-template container.

Check if you can retrieve the hello-world page and you should see a different hostname for every request:

$ curl

Clean up containers:

$ docker rm -f nginx nginx-consul-template hello-world
You can’t perform that action at this time.