Vagrant:
Vagrant is an open-source software product for building and maintaining portable virtual software development environments like VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS. It simplifies the software configuration management of virtualizations in order to increase development productivity. Vagrant is written in the Ruby language.
Download and install Vagrant for your operating system.
To check the installed version of vagrant:
$ vagrant -v
Create a new directory for the project and initialize the vagrant file.
$ mkdir Vagrant ; cd Vagrant/
$ vagrant init centos
It will creates "Vagrantfile" which describes the type of machine required for a project, and how to configure and provision these virtual machines. Below is the simplest Vagrantfile for centos box.
Vagrant.configure("2") do |config|
config.vm.box = "centos"
end
To create the virtual machine and start run below command:
$ vagrant up
For the first run, vagrant will download the mentioned box from the vagrant cloud. To check the status of the machine run below command:
$ vagrant status
To login to the virtual machine:
$ vagrant ssh
To stop the virtual machine:
$ vagrant halt
To restart the virtual machine:
$ vagrant reload
To delet the virtual machine completly:
$ vagrant destroy
To create a public network uncomment below config in Vagrantfile, which generally matched to bridged network. Bridged networks make the machine appear as another physical device on your network.
config.vm.network "public_network"
To create a private network so that the VM has a perticualr IP. We can have both public and private networks.
config.vm.network "private_network", ip: "192.168.33.10"
For updating the RAM allocation to the VM. uncomment below 3 lines and edit "vb.memory" in Vagrantfile.
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
To execute any command or install any packages after installing the VM uncomment below config in Vagrantfile:
config.vm.provision "shell", inline: <<-SHELL
yum install httpd wget git -y
service httpd start
chkconfig httpd on
mkdir /var/www/html/testwebsite/
SHELL
Note: Only for the first time creating the VM it will run the provision commands by default.
To run the provision commands we need to specify while reloading the VM for an existing VM, else it will not run the provision commands everytime while reloading.
$ vagrant reload --provision
We can download differnt box's from vagrant official site.
This looks perfect, as iam looking out Beginner's guide to start using Vagrant.
ReplyDelete