Vagrant – A Introduction

What is Vagrant

Vagrant is a free tool to create and manage virtual machines. It shorts the process of searching for an OS-Image to install and configure in a single command. Vagrant is very similar to docker but the difference is Vagrant is perfect for the automated and reproducible creation of virtual machines. Docker, on the other hand, is the isolated packaging of applications in containers.

Installation

You can download the version for your OS. You can find it here.
After the installation, you need to setup a vagrant folder where we store all our configurations. Also, note that the virtual-machine provider like VirtualBox must be installed on your system.

Initialising and start a VM

Once installed we would like to deploy a VM. We can do this with the vagrant init command.
In our example, we want to deploy a CentOS 8 VM.

vagrant init centos/8

Running the vagrant init-command creates the vagrant file in the current directory, this file has instructions to customize our box. We start the vagrant-box with the command:

vagrant up

Now vagrant downloads the image, creates the vm and configures any settings that we set up in the vagrant file.

To stop the vm run:

vagrant halt

What is a box?

A Box is a packaged format of a vagrant environment. It contains an OS-Image and the scripts to configure the environment. You can find a list of all available boxes here.

Vagrant-file

The vagrant file starts with a configuration block. Here we can setup the image that is used by the box and set up other configurations like port forwarding, cpu and ram settings. When we now run the vagrant up command, vagrant creates a vm based on the configuration in this file. Every time you make changes to the vagrant file we need to reload vagrant. We do this with the command:
vagrant reload

Connect to the VM

It‘s simple like creating the vm we just use:

vagrant ssh

We don’t need another tool to access the vm, even on windows this command works. It’s also possible to setup ssh-key authentication (you can setup this in the vagrant file)

Resume

Well, this is a quick and short introduction to Vagrant. As you can see, it’s a good tool for quickly building small labs or environments and making them available with the appropriate configurations. There are many ways you can do with Vagrant and then share your settings with others.

Automation is becoming an increasingly important topic, so in addition to Docker and Ansible, you should also deal with Vagrant.

🖤 Did this article help you?
Buy me a coffee and support my work to keep this space 🚀 and ad-free. If you can’t, share my work to reach this 📖 out to more people.

Leave a reply

Your email address will not be published. Required fields are marked *