“Mastering Virtualization: A Comprehensive Guide to Creating and Managing VMs with Vagrant”

vagrant

What is Vagrant? Why should we use vagrant? what is a vagrant box and file?

What is a vagrant:

It is a software product that builds and maintains virtual software
development environments. Indeed, the tool is considered to offer one
of the fastest and easiest ways to create a virtual environment

What benefits of using vagrant:

In a single sentence, Vagrant is designed for everyone as the easiest and the fastest way to create a virtualized environment!

Vagrant provides easy-to-configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team

Vagrant Box:

Vagrant boxes are VM images that already have the OS and software installed in them. We just need to download these boxes from the vagrant
cloud by using our Vagrant CLI.Once the box is downloaded you can
create as many VM’s from them.

We can download boxes from this url : https://app.vagrantup.com/boxes/search

Vagrant file:

The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines. Vagrantfiles are called Vagrantfiles because the actual literal filename for the file is Vagrantfile (casing does not matter unless your file system is running in a strict case-sensitive mode). The syntax of Vagrantfiles is Ruby, but knowledge of the Ruby programming language is not necessary to make modifications to the Vagrantfile.

Step by step to create VM with vagrant:

1. For using Vagrant you need to install Vagrant to your computer. To install Vagrant you can follow the link: https://developer.hashicorp.com/vagrant/downloads

2. After successful installation you can verify installation using this command to your terminal: vagrant

3. Here first download the box using this command: vagrant box add kalilinux/rolling

4. Then write the below command. It takes laser time because already we have downloaded it from the cloud and stored it on the local machine. the command is: vagrant init kalilinux/rolling

or you can create a minimal Vagrantfile (no comments or helpers): vagrant init -m kalilinux/rolling

or create a new Vagrantfile, overwriting the one at the current path: vagrant init -f kalilinux/rolling

5. Start virtual machine: vagrant up

Also some commands:

 

==> List the downloaded boxes: vagrant box list

==> Remove box: vagrant box remove box_name

==> SSH into the virtual machine: vagrant ssh

==> Halt virtual machine: vagrant half

==> Destroy your virtual machine: vagrant destroy

Tips: After destroying Vagrant the source code and the content of the data directory will remain unchanged. Only the Virtual Box machine instance will be destroyed. You can build your machine again with the ‘vagrant up’ command.

Leave a Reply

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