Over the past few months I’ve migrated a number of my websites including Blog.BenHall.me.uk to containers and Docker. The main motivation was to reduce the cost of hosting different websites, APIs and databases while allowing me to quickly bring online new domains/sites for testing.
At the start of the 2014 I hosted everything on Rackspace however as my circumstances and the products I worked on changed I looked elsewhere. Having moved away from PaaS offerings like Heroku and Azure due to inflexibility and performance I’ve found a nice home hosting with Digital Ocean. Their performance is amazing and the cost is incredible plus they have a London data centre. My personal referral link will give you $10 credit to get started so you can see the benefits for yourself. For small instances this is equal to one or two months free.
With Digital Ocean I can use Docker where as before I ran a standard Ubuntu, Nginx, WordPress and MySQL configuration. With Docker I still have Ubuntu as the base OS image to keep the configuration simple. For WordPress and MySql I use the official images. The configuration is very straight forward with environment variables and links used to communicate between the two containers. For Nginx I used to use the official repository, however creating configuration files took time and wondered if there was a simpler solution that could take advantage of Docker. The result is Nginx Proxy, an open source project that automates the configuration of Nginx based on Docker metadata. By defining a VIRTUAL_HOST environment variable I can expose a container via Nginx without needing to craft separate configuration files.
While Nginx Proxy is great for a single host but it didn’t support default hosts meaning any domain mapped to the server but without a Nginx setting would return 503. With a simple modification to the Nginx Proxy script I was able to define a DEFAULT_HOST for the server. The change is available at https://github.com/BenHall/nginx-proxy/tree/default_host and https://registry.hub.docker.com/u/benhall/nginx-proxy/
With the combination of Digital Ocean, Nginx Proxy, WordPress and MySQL I have a flexible server to meet my needs with very little maintained required. To ensure my blog is available I use Uptime Robot and Cloudflare.
When I need to bring a new website online I simply point the domain to the server via Cloudflare, create a container which is run with the VIRTUAL_HOST variable. Nginx is automatically configured to handle the new domain. If I don’t have a site available then it’s just parked at my personal blog.