Project: Docker Scaling & SwagIP
My friend Matt Prahl and I decided to work together on some flask stuff. We chose to rewrite http://ifconfig.co in flask.
Matt did an excellent job of ramping up on flask, since he is a PHP guy at heart (we forgive him).
This project looked like an excellent way for me to practice scaling docker applications. So I took the opportunity to do so.
The app itself is very useful. If you are at the commandline and you just need your ip address, you can simply curl/wget/fetch/invoke-RestMethod(Powershell) the application.
Any headers sent are available to be requested as well, such as user-agent and x-forwarded-for. All headers can be pulled with /all.
The WebUI has all the details.
Docker-compose is a tool for container linking and deployment. It is great for multi-container applications. It has this nifty little feature called “scale”. This feature lets you spin up more containers of your application.
Scaling with docker-compose is easy. You just specify which node you want to scale and the quantity! It’s best to throw a load balancer in front of your application.
Here is my docker-compose.yml
haproxy:
image: tutum/haproxy
links:
- web
ports:
- 80:80
web:
build: .
expose:
- 8080
Just a little docker compose magic:
$ docker-compose up
Simple! And with that, I can scale the application up to hundreds of containers.
I made some minor modifications to the app to provide the container id.
(hint: it’s in $HOSTNAME)
Troubleshooting:
I was having issues with getting the haproxy to see the other nodes. It’s best to spin the web containers up before the haproxy:
$ docker-compose scale haproxy=0
$ docker-compose scale web=10
$ docker-compose scale haproxy=1
More can be found at SwagIP project page