Containers in software development compared with Virtual Machines

| In Articles | 21st September 2020

What is a Container

A container is a package or a building block created in a standard format, built to keep all the dependencies, configurations, hooks into the Operation System and the application code itself that need all of that, in the same place. Similar to what a Virtual Machine is doing but there are some differences that we will mention bellow.

Containers advantages compared to what Virtual Machines offers

The reason of all this being stored in a package (Container) is for portability and to remove the compatibility problems when moving an application from one environment to another (for from Development to Production)

Virtual Machines are an alternative

A more complex solution for a Container is a VM (Virtual Machine).
Virtual Machines are older setups that give the possibility of having and running multiple Operating Systems on a single machine (computer) giving a number of advantages that are not the subject of this article.

A Virtual Machine does not have the same portability because it requires software that interacts with the host machine.

Still, in the last years, Virtual Machine became portable once with the possibility of installing an Operation System on a USB flash stick with the help of some required software.

The main difference between a Container and a Virtual Machine is that the Virtual Machine also contain an Operation System, requires a hypervisor and it does not have the same portability.

Advantages of Containers when compared to Virtual Machines

Containers advantages:

  • can be Repeated (used more than once on the same environment)
  • are self-contained execution environments and can run on any Operation System.
  • starting and running them is a lot faster than with a Virtual Machine
  • they use a lot less resources
  • occupies a lot less space on the host machine.

Even if a Container does not require a hypervisor, its processes are talking directly to the kernel and most of them will boot in no more than a couple of seconds.

Other advantages of Containers

  • will always give an operational system (including version control) in a consistent environment which will increase efficiency and development productivity;
  • can also have an Operating System such as Debian as a container image, which will basically give a portable Operation System that can run on any other system along with the project code, dependencies, setups;
  • can help with solving problems related to a developer's workstation as some dependencies can create problems when installed;
  • can also help with productivity, reducing the time a developer needs to spend to setup a project started by someone else and can also help in testing environments making things easy in creating different environments for testing purpose.

Across the internet they are multiple platforms that give premade containers solutions that can speed-up the configuration side of a new project. AWS, Docker and LXC are only a few of these platforms.
A Docker Container can be used into a Virtual machine but not vice-versa.

To create and use a Container with Docker you have to install Docker first on your machine. For Windows less than 10 version the Docker installation is a little bit more tricky, but in Win 10 and Linux things are a lot more simple.

Any project can be moved and setup inside a Container. For a project example that can be used, have a look at the next article that is showing how to create a video lazy list.

For Production, one of the best places where a Container can be deployed and executed is on Amazon Elastic Container Service Amazon ECS, which is a scalable and high-performance service for containers management, which supports Docker and helps with easy running applications stored and configured inside this packages.