Vagrant is a tool for building complete development environments, sandboxed in a virtual machine. Vagrant lowers development environment setup time, increases development/production parity, and brings the idea of disposable compute resources down to the desktop.
With one command, Vagrant does all of the following:
- Creates a virtual machine for you based on an operating system of your choice.
- Modifies the physical properties of this virtual machine (e.g., RAM, number of CPUs, etc.).
- Establishes network interfaces so that you can access your virtual machine from your own computer, another device on the same network, or even from another virtual machine.
- Sets up shared folders so that you can continue editing files on your own machine and have those modifications mirror over to the guest machine.
- Boots the virtual machine so that it is running.
- Sets the hostname of the machine, since a lot of software depends on this being properly set.
- Provisions software on the machine via a shell script or configuration management solution such as Chef, Puppet, or a custom solution.
- Performs host and guest specific tweaking to work around known issues that may arise. For example, Ubuntu 12.04 LTS breaks VirtualBox networking defaults, so Vagrant makes minor modifications to some configuration in Ubuntu to make sure networking continues working. Vagrant does these sorts of things for many host/guest pairs.
This is all completed in about a minute, but the time it takes can greatly increase depending on the software being installed.
Once Vagrant finishes setting up the machine, you are left with a completely sandboxed, fully provisioned development environment. Due to the shared folders and networking, you continue using your own editor and your own browser to develop and test your applications, but the code itself runs on the virtual machine.
Vagrant handles the entire lifecycle of the machine for you, so in addition to setting up your development environment, Vagrant can do all of the following:
- SSH into the machine.
- Halt (shut down) the machine.
- Destroy the machine, completely deleting its virtual hard drive and metadata.
- Suspend or resume the machine.
- Package the machine state so that you can distribute it to other developers.
Vagrant is a Swiss Army knife for development environments. It does everything you need to create and manage them, and helps enforce good practices by encouraging the use of automation and an environment that more closely resembles production.
If there is something Vagrant can’t do with your development environments, chances are that you can extend Vagrant’s behavior through a plug-in to achieve what you need. If this ends up being something that a lot of people need, then your plug-in could be merged back into Vagrant core, since Vagrant itself is open source. Thus, by using Vagrant, you’re using a tool that thousands of developers have contributed to based on their real-world needs.
Some of the Import Commands of Vagrant and its meanings:
box
– manages boxes: installation, removal, etc.cap
– checks and executes capabilityconnect
– connect to a remotely shared Vagrant environmentdestroy
– stops and deletes all traces of the vagrant machinedocker-exec
– attach to an already-running docker containerdocker-logs
– outputs the logs from the Docker containerdocker-run
– run a one-off command in the context of a containerglobal-status
– outputs status Vagrant environments for this userhalt
– stops the vagrant machinehelp
– shows the help for a subcommandinit
– initializes a new Vagrant environment by creating a Vagrantfilelist-commands
– outputs all available Vagrant subcommands, even non-primary oneslogin
– log in to HashiCorp’s Atlaspackage
– packages a running vagrant environment into a boxplugin
– manages plugins: install, uninstall, update, etc.port
– displays information about guest port mappingspowershell
– connects to machine via powershell remotingprovider
– show provider for this environmentprovision
– provisions the vagrant machinepush
– deploys code in this environment to a configured destinationrdp
– connects to machine via RDPreload
– restarts vagrant machine, loads new Vagrantfile configurationresume
– resume a suspended vagrant machinersync
– syncs rsync synced folders to remote machinersync-auto
– syncs rsync synced folders automatically when files changeshare
– share your Vagrant environment with anyone in the worldsnapshot
– manages snapshots: saving, restoring, etc.ssh
– connects to machine via SSHssh-config
– outputs OpenSSH valid configuration to connect to the machinestatus
– outputs status of the vagrant machinesuspend
– suspends the machineup
– starts and provisions the vagrant environmentversion
– prints current and latest Vagrant version