Virtual machines were all the rage fifteen years ago, but they have fallen out of favor in recent years in favor of Docker containers. But each of these DevOps tools has a role to play in the modern business development and deployment process. Here, we’ll compare and contrast Docker and virtual machines and help you determine which one is best for your DevOps needs.
A virtual machine (VM) is a representation of a computer in software. A virtual machine is a computer represented as software on a host machine. Those who use 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.
The way a virtual machine is made is by using a technology called a hypervisor. The hypervisor is the intermediary between the host machine and the virtual machine.
The hypervisor ensures that a number of virtual machines can run on the host computer. In addition, the hypervisor ensures that each virtual machine has its own operating system. This means that you can have a single host machine running Linux while running both a virtual machine with Windows operating system and a virtual machine with Ubuntu Linux on top of the host.
Docker is a technology used to build and run containers. A container is a collection of one or more processes, organized under a single name and identifier, which are isolated from other processes running in an IT environment. This 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 environment. The CLI tool is used to run instructions to the Docker runtime environment on 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 model is called a Dockerfile.
The typical workflow is continuous integration / the continuous deployment process is to use a provisioning tool such as a Vagabond Where Ansible to create a virtual machine in an automation script. Then this automation script will install the host operating system on the virtual machine. Finally, the script will install Docker to allow 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 multiple virtual machines in which each virtual machine has a separate 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 host’s operating system.