Docker versus Virtual Machines: Which DevOps tool is best?
The difference between Docker and a Virtual Machine
Virtual machines were the cock of the walk fifteen years ago, but they have fallen out of favor in recent year in preference to Docker containers. But each of these DevOps tools have a role to play in the modern, enterprise development and deployment process. Here we will compare and contrast Docker and VMs and help guide you as to which of one is the best fit for your DevOps needs.
A virtual machine (VM) is a representation of a computer in software. A virtual machine is a computer that represented as software on a host machine.
Those using a VM think they are interacting with a physical computer but in reality, they are interacting with software emulating a computer. Docker is a technology for running containers on a virtual machine.
Let’s look at the details.
Docker versus VM creation
The way a virtual machine is realized is by using a technology called a hypervisor. The hypervisor is the intermediary between the host machine and the virtual machine.
There are a number of hypervisors available. Many are free. Examples of free, open-source, hypervisors are Virtual Box, Linux KVM, and Xen, to name a few.
The hypervisor makes it so a number of virtual machines can run on the host computer. Also, the hypervisor makes it so each virtual machine has its own operating system. This means you can have a single host machine running Linux yet run both a virtual machine with the Windows operating system and a virtual machine with Ubuntu Linux on top of the host.
VM vs Docker virtualization
Docker is a technology that is used to create and run containers. A container is a collection of 1 or more processes, organized under a single name and identifier that are isolated from the other processes running within a computing environment. That computing environment can be a physical computer or a virtual machine. You can think of a container as a virtual machine for the operating system. A docker container has no life outside of the VM’s operating system.
Docker technology has two main components; the client CLI tool and the container runtime. The CLI tool is used to execute instructions to the Docker runtime at the command line. The job of the Docker runtime is to create containers and run them on the operating system.
A container is created using an artifact called a container image. You can think of a container image as a template that Docker uses to create a container at runtime. The formal artifact that defines the container image template is called a Dockerfile.
The typical workflow is continuous integration/continuous deployment process is to use a provisioning tool such a Vagrant or Ansible to create a virtual machine in an automation script. Then that automation script will install the host operating system on the virtual machine. Finally, the script will install Docker to enable the virtual machine to create and host Docker containers. (See Figure 3, below.)
The important thing to understand about the difference between a Docker container and a virtual machine is that a virtual machine is a software emulation of a computer. A single physical computer can host a number of virtual machines in which each VM has a distinct operating system. Docker on the other hand is a technology that runs containers on a virtual machine. A container has no life outside of the operating system of the host.