Containerizing Monolith Apps Using Docker

If you are a software engineer and not working in some tech backwaters, you must have heard the latest buzz words - containers, micro services, Docker, cloud native apps etc. - all of which essentially points to containerizing your software applications and the benefits you reap from doing so. Containers are all about efficiency - doing more with less. Most of the time your app is using only <~25% (probably even less) of the platform it’s running on, the other ~75% is a waste; unnecessary fat. Don’t believe me? here’s the data :

Monolithic App (My App/Traditional Apps run like this):

Containerized App:

As you can see, the difference in OS footprint is dramatic, because, in a way, you are bundling only the OS that your app ‘needs’ to run. And this is done by containerizing the app - with this approach, you’ll achieve not just resource efficiency, but, other benefits like autoscaling, real elasticity, CI/CD and more. If you are interested in knowing how to containerize a monolithic app, read on ..

Context: My webapp is basically a go-mvc app backed by multiple Redis indexes with Nginx as reverse proxy and whole thing is running on a dedicated ubuntu server (image size of 712+MB) @ digital ocean shielded by cloud flare - hunky dory right ? not so fast. Main issues with this setup are - resource inefficiency (as shown in the first recording) & elasticity, meaning, you can’t quickly [O(ms)] scale up or down based on traffic-even if you are using VMs, it will still take long.

What I did: Created a docker image which contains - essential Ubuntu OS + Platform software (go, revel, redis) + my app + startup scripts. Final docker image has a size of ~117MB (1/7th the size of traditional image). Used Dockerfile reference along the way.

Using the newly built docker image, spin up a container with it’s port bound to port 800 of the docker host :

which is equivalent to scaling up your service by a count of 1 - and this is super fast [O(ms)] - you can use docker compose and docker swarm to do the some hyper masssive autoscaling. With some automation, you can set up event based autoscaling. Now let’s see what’s inside the container:

And here’s the screenshot of my final app running from a container: