Lifecycle
vagrant up [<name>]
Create and start the machine
vagrant halt
Shut down the machine gracefully
vagrant destroy -f
Delete the machine without prompting
vagrant status
Show the machine state of this project
vagrant reload
Restart and re-read the Vagrantfile
vagrant suspend
Save state to disk and pause
vagrant resume
Wake a suspended machine
vagrant destroy -g
Shut down gracefully, then delete
vagrant up --provider <name>
Pick a provider other than VirtualBox
vagrant up --no-provision
Start without running provisioners
vagrant up --parallel
Start several machines at once
Only works if the provider supports it.
vagrant up --no-destroy-on-error
Keep a half-built machine to debug it
By default a fatal error on the first up destroys the new
machine.
Boxes
vagrant box list
List installed boxes
vagrant box add <name>
Download a box
vagrant box remove <name>
Delete an installed box
vagrant box update
Fetch a newer version of the project box
A running machine keeps the old box; destroy and up again to
use the new one.
vagrant box outdated
Check if the project box has an update
vagrant box outdated --global
Check every installed box
vagrant box prune --dry-run
Preview removal of old box versions
vagrant box prune
Remove old box versions
vagrant box add <name> --box-version
<ver>
Add a specific version
vagrant box add <file-or-url> --name
<name>
Add a box from a file or URL
vagrant box repackage <name> <provider>
<ver>
Rebuild a .box file from an installed box
vagrant package
Package the running machine as a box
Snapshots
vagrant snapshot save <name>
Save a named snapshot
vagrant snapshot restore <name>
Roll back to a named snapshot
vagrant snapshot list
List snapshots
vagrant snapshot delete <name>
Delete a snapshot
vagrant snapshot push
Push an unnamed snapshot on the stack
vagrant snapshot pop
Restore and drop the latest pushed one
Do not mix push/pop with save/restore.
vagrant snapshot restore <name> --no-start
Restore but leave the VM stopped
Project and environment
vagrant init -m <box>
Write a minimal Vagrantfile
vagrant init <box> --box-version <ver>
Pin the box version in the file
vagrant validate
Check the Vagrantfile for errors
vagrant global-status
List all known machines with their IDs
vagrant global-status --prune
Drop stale entries from the list
Slow; the list is cached and can show stale state.
vagrant destroy <id>
Control a machine by ID from any directory
vagrant plugin list
List installed plugins
vagrant plugin install <name>
Install a plugin
vagrant version
Show installed and latest version
vagrant <cmd> -h
Help for any subcommand
Vagrantfile
Minimal file
Vagrant.configure("2") do |config| config.vm.box = "<box>" config.vm.hostname = "dev"end
Network and folders
config.vm.network "forwarded_port", guest: 80, host: 8080config.vm.network "private_network", ip: "192.168.56.10"config.vm.synced_folder "./data", "/srv/data"
Provider resources
config.vm.provider "virtualbox" do |vb| vb.memory = 2048 vb.cpus = 2end
Shell provisioner
config.vm.provision "shell", inline: "apt-get update"config.vm.provision "shell", path: "setup.sh"
Ansible provisioner
config.vm.provision "ansible" do |a| a.playbook = "site.yml"end
Two machines
config.vm.define "web" do |web| web.vm.box = "<box>"endconfig.vm.define "db" do |db| db.vm.box = "<box>"end