Since becoming a Racker back in 2007, one of my all time favorite websites has been slumlordhosting.com. Slumlord Hosting is a parody of really bad shared hosting environments, advertising some amazing features:
- Dedicated space on a “High Density Floppy Storage Area Network Device”
- A duel (sic) channel ISDN line for maximum bandwidth
- 10MB of dedicated space
On top of the features listed above, the website itself is glorious. Looking at it recently, I began to think to myself, “If I were running a business like this, what could I use to squeeze every possible resource out of a server and offer it up for shared hosting?” Enter Cloud Servers and Docker. My strategy is simple: build a Cloud Server, install Docker, and then create as many containers as possible. I’ve decided to use WordPress containers since WordPress is extrememly popular.
Running a hosting business based on how many containers you can squeeze on a server is definitely NOT RECOMMENDED and is more for fun while we play with Docker.
What is Docker?
Docker is a very, VERY popular open source project. Since the project was open sourced only a few months ago, Docker has over 4800 stars, 490 forks, and over 300 watchers on GitHub. There are over 100 contributors. So what does Docker do? From the Docker website:
Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere.
Docker containers can encapsulate any payload, and will run consistently on and between virtually any server. The same container that a developer builds and tests on a laptop will run at scale, in production, on VMs, bare-metal servers, OpenStack clusters, public instances, or combinations of the above.
Now that we know what Docker is, let’s look at how to implement it for our purposes as a hosting slumlord.
To install Docker, I will need a Rackspace Cloud Server. I’m starting with Ubuntu 13.04 and my SSH key for easy login:
Notice I am also using the smallest server available: 512M of RAM. This is way too much by slumlord standards, but at least I can have more containers. When the server is up, install Docker:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
If you want to know more about what you just did, take a look at the Docker documentation. Now that Docker is installed, I need to create a WordPress Docker container.
Creating a WordPress Container
For this I forked a project on GitHub called ”docker-wordpress” written by John Fink. Why fork? To use Ubuntu 13.04 of course! To create a WordPress container, run the following commands:
1 2 3 4 5 6 7 8
This will build a WordPress docker container and run it. You can browse to your Cloud Server IP address and port that Docker provides to get a WordPress installation page. Let’s take a look at the Dockerfile that makes the magic happen:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Basically this Dockerfile installs packages we need, puts scripts in place for us, and downloads and unpacks WordPress. The
start.sh script sets up a WordPress MySQL database and generates passwords, while the
foreground.sh script starts Apache. Docker doesn’t let you start services using
service some_service start or
/etc/init.d/serviced start, so here we’re using supervisord to start services for us. The Dockerfile also makes sure that port 80 is available externally for our web server, and 22 is open so we can SSH to the container. These ports will be connected to a port on the host machine.
You can see a lot of information about the running container with the
Now it’s time to make this available for customers! Go ahead and kill this docker contatiner. Our application will make more later:
The Slumlord WordPress dashboard is also a forked project on GitHub. The original project was a proof-of-concept SaaS application for Memcached. We’re using it here for our nefarious slumlord purposes. First we need to install dependencies:
1 2 3
Once you have the dependencies installed, clone the front end repository:
1 2 3
Then we need to create the database and start the rails server:
You can set this application up to run with Unicorn/Passenger/Thin/whatever app server if you like but that setup is outside the scope of this post. Navigate to the IP address of your server on port 3000 and marvel at Slumlord WordPress.
When a user clicks the “Sign Up Now” button and creates an account, a docker container with Apache, PHP, MySQL and WordPress is created from the template container we made earlier.
What if a customer wanted to leave Slumlord WordPress and migrate away? While the probability of this is close to zero, Docker makes it easy:
The container in its current state can then be moved to a different server running Docker and started back up. Lucky for the slumlord, if a customer wants to sign up with your service, this helps you as well!