Suitability of containers over virtual machines

Let's understand the difference between containers and virtual machines—at the surface level, both are tools to achieve isolation and virtualization. 

The architectural difference between virtual machines and containers is quite evident from the following diagram:

By looking at the virtual machine internals, we can see that there is a host operating system along with a kernel, and on top of it, the hypervisor layer. Hosted applications have to bring in their own operating system and environment. In containers though, the containerization technology layer serves as a single layer and is shared across different applications. This removes the need for a guest operating system. Thus, applications in a container come with a smaller footprint and strong isolation levels. Another aspect that will encourage you to use containers for microservice deployment is that we can pack more applications on the same physical machine when compared to the same applications deployed on a virtual machine. This helps us achieve greater economy of scale benefits and provides a comparison of the benefits of virtual machines. 

One more thing to note with containers is that they can be run on virtual machines as well. So it is okay to have a physical server with a virtual machine on it. This virtual machine serves as a host to a number of containers.