Developing robust software requires an accurate testing and staging environment. Vagrant provides just that. It lets you mimic your production server map on your computer.
Creating the Vagrantfile
Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
vagrant init boxpath
Initialize Vagrant with a specific box. To find a box, go shopping. When you find one you like, just replace it's name with boxpath. For example, vagrant init chef/centos-6.5.
vagrant.configure("2") do |config|
config.vm.box = "chef/centos-6.5"
# guest is the VM; host is your computer end
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provision :shell, path: "my_bash_script.sh"
# path is relative to your Vagrantfile
By default ./ on your computer is shared as /vagrant on the VM. Letting other people access your VM's
vagrant box list
List the installed boxes
vagrant box add <name> <box path/HTTP URI>
Add the box for later use
vagrant box remove <name> virtualbox
delete a box
vagrant box outdated
Check for updates vagrant box update
Boxes are prebuilt VM images. You never modify your box images
Common Vagrant Commands
starts vagrant environment (also provisions only on the FIRST vagrant up) Equivalent to pressing the power buttons on your servers.
outputs status of the vagrant machine
stops the vagrant machine
restarts vagrant machine, loads new Vagrantfile configuration
forces reprovisioning of the vagrant machine
connects to machine via SSH
stops and deletes all traces of the vagrant machine
Suspends a virtual machine (remembers state)
Resume a suspended machine (vagrant up works just fine for this as well)
vagrant reload --provision
Restart the virtual machine and force provisioning
vagrant provision --debug
Use the debug flag to increase the verbosity of the output
Be sure that you are in the same directory as the Vagrantfile when running these commands!
Get the vagrant version
outputs status of all vagrant machines
vagrant global-status --prune
same as above, but prunes invalid entries
vagrant up --provision | tee provision.log
vagrant up, forces provisioning and logs all output to a file
VAGRANT_LOG=info vagrant up
Use the environement variable VAGRANT_LOG to set verbosity
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!