The last few days, I was busy getting started with Vagrant. Vagrant is a nice tool to create a development environment to ‘just start’ developing. New team members, for instance, do not need to set up, but can simply run ‘vagrant up’ to have a fully configured, ready-to-start environment.
Personally, in my case, it is very helpful with my PHP development environment. I do not need to care about PHP extensions (intl, mcrypt, dom, etc). My Vagrantfile will contain all these setups. I just need to run ‘vagrant up’.
The following list is a summary of Vagrant and how to use it, based on the “Getting Started by Vagrant” article:
- lowering development environment setup time
- stands on shoulders of giant: machines provisioned on top of VirtualBox, VMware, AWS, etc.
- allows automatically installing software, alter configuration etc. as part of the ‘vagrant up’ process
- installing needed software by hand works, but provisioning allows automation of that.
- all you need for a fully ready-to-go system is ‘vagrant up’ and ‘vagrant destroy’
- provisioning runs at the first ‘vagrant up’, with ‘vagrant provision’ and if flags are set
- inline or external shell script
Ruby1config.vm.provision :shell, path: "bootstrap.sh" # as part of Vagrantfile’s ‘configure’
- ‘Box’: base virtual machine image to quickly clone a VM.
- ‘Box Catalogue’: central place to store boxes
- isolates dependencies in an environment without affecting any of tools used (editor, IDE, browser, etc)
- every configuration is done by Vagrantfile: two purposes
- marks the project root, many options are related to this path
- describes kind of machine and software to install needed by your environment
- Vagrantfile meant to be commited to the VCS
- ‘synced folders’: Vagrant syncs automatically files to/from host/guest machine
- ‘vagrant up’ also provisions
- ‘vagrant reload –provision’ when guest machine is already running
- ‘vagrant init’ initializes a directory for usage with Vagrant
- configuring a box in Vagrantfile:
Ruby12345Vagrant.configure(“2”) do |config|config.vm.box = “hashicorp/precise64”config.vm.box_version = “1.1.0”config.vm.box_url = "https://vagrantcloud.com/hashicorp/precise64"end
- config.vm.box_version and config.vm.box_url are optional
- CTRL + D: Logout from VM
- ‘vagrant box remove’ removes downlaoded box
- 3 Major ways to teardown your environment:
- ‘vagrant suspend’: saves the current running state of the machine and stop it. ‘vagrant up’ gets it back. Downside: eats up diskspace as it stores all the state of the VM.
- ‘vagrant halt’: shuts the guest operating system gracefully down and powers down the guest machine. Downside: takes much more time to boot the VM again.
- ‘vagrant destroy’: stops the guest machine, powers it down and removes all traces of the guest machine from your system. Benefit: no cruft is left on host (especially RAM and disk space). Downside: takes extra time to boot with ‘vagrant up’, as it has to re-import everything and provision.
- Vagrant Share – let’s you share your environment with the whole world
Last Update at 14/03/2019 12:38:42. Change Description: initial document