loading...

November 19, 2018

Docker vs. Virtual Machines

Docker is used for software development and deployment. This article describes structures of container and VM systems.

Docker is very famous for both software development and deployment; it is used everywhere. The idea is to use the same environment on each machine in the whole cycle of software development and deployment. Previously, it was already possible to simulate the production environment with virtual machines (VMs). So what is this concept of VMs and how is Docker different from VMs?

Problem of Programming and Deploying on Different Machines

Programming happens on the developer’s local machine. Usually, this machine has a different setup from the machines of other developers and the servers where the programme should be deployed on. These environments behave differently and code which worked on one machine might not work on another machine. Therefore, the idea is to create the same environment on all the machines involved.

Concept of Virtual Machines

The idea of VMs is to simulate a complete computer. Working on a VM is like working on another computer. Additionally, you could run multiple VMs on one computer. Each VM of the developers should be set up like the servers used in production. Then, problems that arise because of varying development environments and the differences between development and production environments will not occur anymore.

The repository used for development also includes a Provisioning File describing how the environment should be set up (which software should be installed). This file is used to set up the VM of each developer and the remote servers where the software should be deployed on. The code is still shared via a VCS (e.g. Git) and, finally, deployed on the servers.

A provisioning script describes how to set up the different (virtual) machines. Than, the code could be run on all these machines which have the same environment.
Concept of Virtual Machines for Software Development and Deployment

Concept of Docker

Docker has a different idea. When installing Docker, the Docker Daemon is installed automatically. The Docker Daemon does not serves as a virtual machine but it controls the containers. It should run when using docker. In this case, the previously mentioned Provisioning File is called Dockerfile. Its content describes how to build an image with the Project Code. The image serves as a blueprint for containers which could run on any machine with Docker. This image could be published in a registry (e.g. Docker Hub). Then, an image could be pulled from the registry and run on any machine. For collaboration between different developers, the code is still shred via a VCS (e.g. Git).

Docker builds images which serve as a blueprint for the its containers. These images are shared via a registry like Docker Hub and their containers could be run anywhere.
Concept of Docker for Software Development and Deployment

Comparison Between Docker and VM Systems

The main difference between Docker (in general, container system) and VM systems is that Docker creates containers running on the machine; the binaries use the same kernel like the OS. Whereas VM systems create complete new machines with an own OS on the host system. This results in a redundancy of operating systems and, therefore, in a waste of resources.

Docker spins off containers that run on the Host OS. VM systems create new VMs running on the host.
Comparison of Docker and VM Systems

The diagram shows only one application running in each VM but several applications could be run in a VM.

However, the encapsulation of VMs is stricter and results in a higher security. Thus, putting together the two technologies would minimise the disadvantages of each technology while combining their advantages.

Combining VMs and Docker results in using the advantages of both technologies.
Combination of Docker and VM Systems

In this example, several VMs are run on the Host OS. Each VM could run multiple Docker Containers. Though, a VM does not have to run any Docker container; it could also be used without any container technology.

Even though Docker is very famous and nearly omnipresent, there are many alternative container systems and also systems used for the management of images and containers created with Docker.

Posted in GeneralTaggs: