Vagrant vs Docker — The Untold Secret To Mastering Hashicorp Vagrant In Just 3 Days

We will discuss in this article basics of vagrant for anyone interested in learning about emulated and isolated virtual machines.
We are going to do a deeper dive into how to get started creating virtual machines on your machine.
Vagrant is a software built to Isolate dependencies and create a single disposable and consistent environment. When compared to Docker containers, these environments are more isolated.
First off, we will install the software Vagrant from Hashicorp on our machine. To install visit the downloads page and select your Operating System.
Next we will decide on which Provider Vagrant will use.
Picking between Docker and Virtual box is difficult. For lightweight workloads you may decide to use Docker as your provider. For heavyweight workloads Oracle Virtual box is a better choice.
The only requirements needed before setting up environments is creating a a VagrantFile.
We will describe this file in more detail below.
How to switch Providers in Hashicorp Vagrant
This file will setup an isolated environment using a provider of our choice.
Define Docker as your provider in VagrantFile
In this example, we will define a VagrantFile for Docker.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.provider "docker" do |d|
d.image = ""
d.has_ssh = true
end
endDefine Virtual Box as your provider in VagrantFile
In this example, we will define a VagrantFile for Virtual Box.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# name vm machine
config.vm.define ""
config.vm.hostname = ""
config.vm.provider "virtualbox" do |d|
config.vm.box = ""
end
endWe these secrets revealed, you can now work with virtual machines in a declarative way using the following commands.
How To Find a VM Box
Before you can run the start commands for vagrant you will need to define a box for your VagrantFile to spin up. Let’s look for a new Box that we can work within.
vagrant box list
The output should look like similar to this:
bento/centos-7.2 (virtualbox) bento/centos-7.3 (virtualbox) ...
How To Start and Stop a Vagrant VM
The following commands will be used any time you choose to use VagrantFile’s to configure you machines.
To get a VM to spin up you simply need to run.
vagrant up
To get a VM to spin down and purge your VM, you simply need to run the following command.
vagrant destroy -f
Happy Coding!! Hope you find this insightful and delightful!
P.S. If you’re a fan of Medium as much as we are, consider supporting me and the thousands of other writers by signing up for a membership.
It only costs $5 per month, and it supports us writers. Thank you, Greatly.

