avatarSteven Rescigno

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1916

Abstract

ss="hljs-number">2</span>) <span class="hljs-keyword">do</span> |<span class="hljs-params">config</span>| config.vm.provider <span class="hljs-string">"docker"</span> <span class="hljs-keyword">do</span> |<span class="hljs-params">d</span>| d.image = <span class="hljs-string">""</span> d.has_ssh = <span class="hljs-literal">true</span> <span class="hljs-keyword">end</span> <span class="hljs-keyword">end</span></pre></div><h2 id="005b">Define Virtual Box as your provider in VagrantFile</h2><p id="991e">In this example, we will define a <b>VagrantFile for Virtual Box.</b></p><div id="6336"><pre><span class="hljs-comment"># -- mode: ruby --</span> <span class="hljs-comment"># vi: set ft=ruby :</span>

<span class="hljs-title class_">Vagrant</span>.configure(<span class="hljs-string">"2"</span>) <span class="hljs-keyword">do</span> |<span class="hljs-params">config</span>| <span class="hljs-comment"># name vm machine</span> config.vm.define <span class="hljs-string">""</span> config.vm.hostname = <span class="hljs-string">""</span> config.vm.provider <span class="hljs-string">"virtualbox"</span> <span class="hljs-keyword">do</span> |<span class="hljs-params">d</span>| config.vm.box = <span class="hljs-string">""</span> <span class="hljs-keyword">end</span> <span class="hljs-keyword">end</span></pre></div><p id="f36c">We these secrets revealed, you can now work with virtual machines in a declarative way using the following commands.</p><h1 id="a3e9">How To Find a VM Box</h1><p id="f009">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.</p><div id="0579"><pre>vagrant box list</pre></div><p id="11e7">The output should look like similar to this:</p><div id="7738"><pre>bento/centos-7.2 (virtualbox)

bento/centos-7.3 (virtualbo

Options

x)

...</pre></div><h1 id="4f9f">How To Start and Stop a Vagrant VM</h1><p id="29da">The following commands will be used any time you choose to use VagrantFile’s to configure you machines.</p><p id="740a">To get a VM to <i>spin up</i> you simply need to run.</p><div id="1438"><pre>vagrant up</pre></div><p id="e6f8">To get a VM to<i> spin down</i> and purge your VM, you simply need to run the following command.</p><div id="3b5a"><pre>vagrant destroy -f</pre></div><p id="74c9">Happy Coding!! Hope you find this insightful and delightful!</p><p id="bc44"><b>P.S. </b>If you’re a fan of Medium as much as we are, consider supporting me and the thousands of other writers by<b> <a href="https://srdbranding.medium.com/membership">signing up for a membership</a>.</b></p><div id="80c3" class="link-block"> <a href="https://srdbranding.medium.com/membership"> <div> <div> <h2>Join Medium with my referral link - Steven Rescigno</h2> <div><h3>Read every story from Steven Rescigno (and thousands of other writers on Medium). Your membership fee directly supports…</h3></div> <div><p>srdbranding.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*NXSej3uXkTCYcRyb)"></div> </div> </div> </a> </div><p id="c4be">It only costs $5 per month, and it supports us writers. Thank you, Greatly.</p><figure id="ef21"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*R-6qKPcrXOQsJsn1.png"><figcaption></figcaption></figure><h2 id="ef5e">👋 If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇</h2><h2 id="5adc">🚀Join FAUN Developer Community & Get Similar Stories in your Inbox Each Week</h2></article></body>

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
end

Define 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
end

We 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.

👋 If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇

🚀Join FAUN Developer Community & Get Similar Stories in your Inbox Each Week

Vagrant Vs Docker
Hashicorp
Vagrantfile
Vagrant
Docker
Recommended from ReadMedium