Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the "works on my machine" excuse a relic of the past.
Vagrant allows you to work on any project, install every dependency that the project needs, and set up any networking or synced folders, so you can continue working from the comfort of your machine.
Prerequisites:
Hands-on Lab Overview
This hands-on lab focuses on the creation of a development environment with Vagrant which uses CentOS/7 as a base image.
Hands-on Lab
To initialize a new Vagrant environment by creating a new Vagrantfile, run the command:
vagrant init
Configure the project to use "CentOS 7" as a base image. Open the newly created Vagrantfile and edit the line:
config.vm.box = "centos/7"
💡Vagrant uses a base image to quickly clone a virtual machine, instead of building a virtual machine from scratch, which would be a slow and tedious process. Search for the required box at https://app.vagrantup.com/boxes/search.To bring up the virtual machine running CentOS 7, enter the command:
vagrant up
With just one line of configuration and one command in the terminal, a fully functional, SSH-accessible virtual machine was brought up.
Vagrant runs the virtual machine without a UI, therefore it is not possible to see anything. To prove that it is running, SSH into the machine.
vagrant ssh
This command will drop into a full-fledged SSH session.
Terminate the SSH session with
CTRL+D
, or by logging out.Once you're back on your host machine, stop the machine that Vagrant is managing and remove all the resources (disk space and system resources) created during the machine-creation process. When prompted, confirm with a
yes
.vagrant destroy
This command does not remove the downloaded box file.
To list box files:
vagrant box list
To remove the box file, run the
remove
subcommand, providing the name of your box:vagrant box remove centos/7