Vagrant and Docker both provision resources needed to support cloud-native deployments, though they focus on different parts of the deployment stack. Developers use Vagrant to provision VMs upon which a Linux container can run. Docker is itself one of the containers that can be installed on one of these VMs created by Vagrant.
Essentially, Docker is a technology for creating and running Linux containers, and Vagrant is a machine provisioning tool used to create VMs and then populate them with applications. In other words, you use Vagrant to create a VM and install Docker. Then, once Docker is installed, that VM can run containers.
Docker is a technology that is used to create and run containers. A container is a collection of one 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 VM.
Docker technology has two main components: the client command-line interface (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.
Docker uses two main artifacts that are essential to container technology. One is the container image. The other is an actual container. A container image is a template upon which a container is realized at runtime, as shown in Figure 1 to the left.
A container has no life of its own outside of the operating system. Thus, in terms of an automated CI/CD process and in order for Docker to work, a real or virtual machine with an OS must exist. Also, that machine must have the Docker runtime and daemon installed. This is where Vagrant comes into play.
In order to support CI/CD in an automated deployment environment, you need a way to run scripts that create VMs, and then populate them with an operating system and other applications that are required to fulfill the VMs' purpose. The way you do this is by using a provisioning tool. Vagrant is one such tool; however, there are others that perform similar tasks, such as Ansible and Terraform.
Under Vagrant, a provisioning script is named, Vagrantfile. The following shows a sample Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "generic/ubuntu1904"
# Install Docker
You execute a Vagrantfile script using the command:
When you run this command, by default, Vagrant looks in the current directory for the Vagrantfile and executes the instructions in the file. Typically, the instructions include creating one or many VMs, installing an operating system on the machines, and then adding the other required applications, such as the Docker components.
Figure 2 below is an illustration that conceptually describes a Vagrant workflow process.
The important difference between Vagrant vs. Docker is that Docker is used to create and run Linux containers, while Vagrant does the work to provision a machine with an operating system, a Docker installation and any other application that needs to run on the OS.
Dig Deeper on Java DevOps
Related Q&A from Bob Reselman
The Kubernetes command-line tool, kubectl lets you control your Kubernetes clusters. But two of its operations -- apply and create -- can often be ... Continue Reading
Some DevOps professionals shun industry certifications. But in the cloud-native world, Docker and Kubernetes certifications make prospective job ... Continue Reading
To succeed in cloud native development, developers need to know their way around Kubernetes and Docker. Here are the basics on these two container ... Continue Reading