In the last 15 years, it has become exponentially easier to deploy and manage web applications.
First, services like Amazon Web Services allowed you to easily rent a portion of a server via virtual machines. Rather than, you know, buying the whole server and running it from your closet.
And now, you can use services like Docker, which use containers to make it even cheaper and easier to manage dynamic web apps.
But, new web developers often get the two underlying technologies (virtual machines and containers) mixed up. Although they both make it much easier to deploy web applications, they have some significant differences.
In fact, it’s kind of like the difference between renting your own office space and renting coworking space (using a company like WeWork). So, this tutorial will use the office example to show how they are different.
In order to understand this tutorial, you must first understand the concept of AWS and virtual machines. Check out my separate guide to AWS if you need to review that first.
Now, imagine that you are the owner of a small software company (5 employees) and you are looking for office space.
Let’s rewind 20 years to the year 2000. If you were searching for office space as a small software startup, your options were likely very limited and cost prohibitive. You could:
- Buy a small office in a strip mall (or something like that)
- Sign a multiyear lease with a significant upfront payment
You would face similar difficulty with getting your product online. You would need to buy an entire server, store it somewhere, and make sure it stayed online 24/7. Very inefficient.
But, over the last 20 years, your choices for renting office space have changed! As tech startups became more popular, you could rent a portion of an office on a one year lease, or even a month-to-month lease.
And, as coworking spaces became trendy in the 2010s, you could just rent a desk or a closed room within a space shared by many companies at once!
At the same time, this was also creating a different relationship between the office building itself, and the team of people required to run the building.
When you purchased the entire office at once, you needed to also manage all the services needed to run the space- snacks, cleaning, furniture etc. If the physical space is like hardware , the office services are like software. And the office manager is the operating system (OS), since they determine how the office works.
But, as we have made office space more accessible, we have also greatly increased the complexity of office services. In other words, there are a greater number of operating systems that must work together.
For example, let’s say your company begins to rent a floor of a larger office building. Now, there must be a general office coordinator to manage all the floors, and you must have your own office coordinator to manage the services for your floor!
Okay, let’s be honest, it’s a small company so that means the CEO is probably the office coordinator for their floor.
Now, each CEO needs to figure out the operating system for their office- which snacks, when it will get cleaned, and any furniture that is needed.
It’s a heck of a lot better than needing to buy real estate, at least.
Let’s tie this back to virtual machines and containers.
Much like our second scenario, virtual machines add their own operating system on top of the existing operating system on the server.
And, they must use a layer of middleware called a hypervisor to allow each virtual machine to share the hardware capacity.
It kind of looks like this:
So, there are three levels of software that must work together alongside the files in your application:
- Host OS
- Guest OS
There are certainly some advantages here- for example, each virtual machine can run its own operating system, which adds more flexibility. But, it also adds a series of resource-intensive software layers.
Let’s return to the office space example to learn about using containers. Imagine the year is now 2015, and coworking spaces like WeWork have become popular.
At these coworking spaces, you simply need to start paying a month-to-month lease per desk. The property managers take care of snacks, cleaning, furniture and everything else.
In other words, you are able to benefit from the space’s existing operating system!
Here’s what that looks like:
Great! Now each CEO can focus on just running their company.
In fact, this is the key distinction between containers and virtual machines- as you can see in the diagram above, containers share the host operating system. That means they do not need to run their own OS, or work with a hypervisor to distribute hardware resources across multiple operating system.
This means that containers tend to be much more scalable than virtual machines- you can easily deploy new containers in a standardized environment with fewer points of failure. It’s also more cost-effective since you do not need to pay to run all the extra software.
Keep in mind, there are hundreds of servers on AWS that are running the exact same OS all around the world. That means that you can easily manage containers with your web app all around the world, with very little overhead or custom setup.
There is one major disadvantage to containers- security vulnerabilities. Each container has root access to the server, so problems that start with one container on a server can then affect others as well.
Let’s return to the original point of this article- Docker allows developers to create and manage containers.
So, in our analogy, the Docker service isn’t the building itself- that’s hardware (servers) and Amazon Web Services. And it isn’t an individual company that rents space- those are like containers.
In this case, Docker is like the coworking space management company- they make it possible for you to rent office space (or server space) in a new way!
Interested in using other similar tutorials? Check out the CodeAnalogies blog for explanations of other common webdev topics.
This website, DEV, is a social media platform designed specifically for developers.