This is a demo using:
- docker
- docker-compose for composition
- consul for service discovery
- registrator to automatically feed consul with new containers
- tutum/hello-world as the demo application
First, launch the consul/registrator/haproxy base infrastructure with:
$ docker-compose -f consul.yml up -d
You will then be able to see:
- the consul dashboard at http://consul-admin.127.0.0.1.xip.io
- the haproxy dashboard at http://proxy-admin.127.0.0.1.xip.io
Then launch the hello-world application with:
$ docker-compose up -d
which will let you access:
- the running application at http://hello-dev.127.0.0.1.xip.io
the web_1
node was also added to:
- the consul dashboard as a service node
- the haproxy dashboard as a backend
If you type:
$ docker-compose scale web=2
You will see:
- A new node added to the consul dashboard
- A new backend added to the haproxy dashboard
- A changing ID when refreshing the application page
Health checking is implemented at two levels in this stack:
- haproxy checks that port 80 of each member is up
- consul checks that the node is up and that
/
returns a 200 status
If either check fails, the node will not be proxified.
You can test the HTTP check with:
$ docker-compose scale web=3
$ docker exec -ti $(basename $PWD)_web_2 pkill php-fpm
This will kill the php-fpm
master process of the second container:
- The
web_2
node will be shown in error in the consul dashboard - The
web_2
node will not appear anymore in the haproxy dashboard - The service will still run on the two other instances
To fix it, kill the container and scale again:
$ docker rm -f $(basename $PWD)_web_2
$ docker-compose scale web=3
-
Test with an overlay network and:
- get rid of links
- use consul DNS instead of links
-
Test on swarm
-
Port to an AWS ECS stack with CloudFormation