Introduction
As discussed several times through my articles (i.e Docker), containers are now very popular and a lot of development and programs are moved to them. You can see on this graph Docker popularity over yeards :
However, in some case, using VM still makes sense ! We will try to compare both technologies and find together, in which case you should use containers and in which case you should still use Virtual Machines.
Here is a quick reminder of both components :
Why you should use containers ?
Start time
Containers start in few seconds, whereas virtual machines can take minutes ! Thus, workloads that need to start very quickly fit perfectly on Docker.
Efficiency and Cost
When you create your Docker image, you can configure a minimum installation. So you will take less disk space and consume less CPU or RAM with containers. Your containers and images will be optimized and dedicated to a specific task. It also means that you will save money by consuming less cloud ressources ! Finally, most of technologies using containers are free and open souce so we can definitively say that you will reduce costs drastically.
Continuous Integration, Deployment, and Testing
If you are familiar with CI/CD, you will be convinced that Containers are amazing and perfect for it. Containers are particularly useful in developing, deploying, and testing modern distributed apps and microservices that can operate in isolated execution environments on same host machines. With containerization, developers don’t need to write application code into different VMs operating different app components to retrieve compute, storage, and networking resources. A complete application component can be executed in its entirety within its isolated environment without affecting other app components or software. Conflicts within libraries or app components do not occur during execution and the application container can move between the cloud or data center instances efficiently.
Why you should (still) use VMs ?
Security
In 2018, 60% of organizations suffered a security incident specific to containers, according to Tripwire. It can be related to bugs, poor authentication and authorization, and even misconfiguration.
Virtual machines are more isolated from each other and from the host system than are containers. That is because virtual machines don’t directly share any kernels or other resources with the host system.
Mixed OS environment
Docker is not portable. It means that you can’t have on the same host Windows and Linux containers. Docker containers for Linux only work on Linux hosts, and the same holds true for Windows. Which is not the case with virtual machines. This portability is handy if you have an infrastructure where you need to be able to deploy one type of operating system on another. Finally, Docker only works on certain versions of Windows !
Rollback features
Many modern virtual machine platforms make it easy to “snapshot” virtual machines at a given point in time, and to “roll back” a machine when desired. This can be useful when dealing with data corruption or security breaches, among other issues.
Docker doesn’t offer the same type of functionality. You can roll back container images, but because containers store their data outside of the image in most cases, rolling back an image won’t help you recover data that was lost by a running application.