Advice on using docker to offer a saas based web application

I have worked with a certain php and mysql based crm application for a while as a developer and know it inside out. I have an idea to offer an on-demand saas based hosted version where the client and can purchase a plan based on the number of users. They will simply click a button and this will automatically spin up and deploy a brand knew instance of the application for them and they will then be able to log in and use the software but wont have any access to the actual web space apart the ability to download a dump of there data anytime they want. It will automatically assign a sub-domain and email them their login details when its ready. I basically want it to be as autonomous as possible.

I think I have three possible ways to go about this:

We’ll use digital ocean as an example provider

  1. I could have one or multiple VM’s or droplets and set up each user’s software in a different virtualhost - this way I can host multiple instances of the software on each droplet lowering costs.
  2. Create a new droplet for each user - this provides additional flexibility and is easier to configure but is a bit more costly.
  3. Use Docker and some sort of scalable cloud hosting and set up each users software in a different container.

Obviously by posting here I am looking at number 3 but realistically is this a viable option?

The way I understand it is I would use a docker container to hold the application code itself, Apache and php. I would then have a separate container to run mysql and hold all the databases. Then every time a customer signs up I would spin up another application container and create a new database in the mysql container. I also have separate container holding nginx to act as load balancer between all different containers. If my node/droplet started to struggle I could then just scale up using the cloud hosting to cope.

Does this sound right so far?

The application itself is customizationable and users could install modules and change layouts that would change the structure of the applications files. So I would need to be able to maintain this between container restarts as well as maintain their databases long term. I understand that we use volumes for this? but is putting the entire php file structure of the application into a volume on each container viable?

I would also need a way to upgrade application on mass as new version come out obviously the customers would need to be kept up to date.

Does all this sound feasible with docker?

You are on the right track. Containers should be immutable so if customers are going to be allowed to install plug-ins or make configuration changes, these must be mapped to external volumes either on a VM or some form of persistent storage. If the application doesn’t save all of it’s changes in one place then the best thing to do is map the entire php file structure to an external volume. Not ideal but thats what poor application design costs in the end.

If you are planning to share a mysql instance and host multiple databases, I would host that on a separate VM for storage purposes. You can still use Docker to run the database engine but using a single VM will make it easier for you to backup and restore database for customers.

As for making updates, if all configuration data is mapped to external volumes, you should be able to replace the customers containers with the latest version and not loose anything using blue/green deployment techniques. If, however you need to map the entire php filesystem because of data stored all over the pace, you will loose the ability to make updates cleanly. In fact, the more I think about it, if the application can’t externalize it’s data cleanly, this might not be worth it. It is difficult to containerize monolithic apps that are sloppy with their data files.

If you really want to keep your maintenance low, I would use a PaaS provider that offers a container cloud that will manage the containers for you instead of you setting up VM’s and nginx load balancers etc. IBM Bluemix has a Docker container cloud where you could deploy a container group and it will automatically assign a load balancer and you could increase and decrease the number of containers manually or set min/max/desired limits and Bluemix will automatically manage it for you based on load. Bluemix also has external Object Storage that you can bind to your containers to map volumes onto. Finally, Bluemix has the ability to perform blue/green deploys. It has a service called Active Deploy that will migrate from one version of a container to another gradually replacing instances while they are running.

So yes, all of this seems feasible with Docker and is made easier by using a container cloud and not rolling your own with VM’s, but if the php application was written sloppily modifies files all over the place, this may not be the right app for containerization. Just something to consider.

~jr