Vagrant

VAGRANT

the command line utility for managing the lifecycle of virtual machines.
Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology.

generate Vagrantfile

vagrant init

If you need to configure project, you can edit Vagrantfile. Vagrantfile is placed project directory that you executed vagrant init.


deploy vm

vagrant up

connect vm

vagrant ssh

logout commandė”œ connection close


destroy vm

vagrant destroy

remove box file

vagrant box remove

synced folders

By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.


provision

add bootstrap.sh file in the same directory as Vagrantfile

#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -fs /vagrant /var/www
fi

edit Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
end

vagrant up
or
if guest machine is already running

vagrant reload --provision

port forwarding

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, guest: 80, host: 4567
end

Run a vagrant reload or vagrant up


teardown

suspending

save the current running state of the machine and stop it.

vagrant suspend

halting

shut down the guest operating system and power down the guest machine.

vagrant halt

destroying

remove all traces of the guest machine from system.
stop the guest machine, power it down, and remove all of the guest hard disks.

vagrant destroy

rebuild

vagrant up

providers

default option is backed with VirtualBox.
If you want to work with another backend provider, just vagrant up with the proper provider.

vagrant up --provider=<<provider name>>

you can use vmware_fusion, aws and more as provider name.