A simple vagrant Cheat Sheet
Vagrant is an open-source tool that is used to manage a development environment. Through the command line, you can grab any available OS, install it, configure it, run it, work inside of it, shut it down, and more. Essentially, it is a layer of software installed between a virtualization tool (such as VirtualBox, Docker, Hyper-V) and a VM.
This article provides a quick cheat sheet with almost everything you need to know about configuring and managing Vagrant.
This article assumes that you already have Vagrant installed on a local machine or at least access to a system where Vagrant is installed.
NOTE: For almost all of the following commmands, you'll need to be in a Vagrant directory containing a Vagrantfile
and .vagrant
directory.
Creating a VM
vagrant init
-- Initialises Vagrant. This creates aVagrantfile
and./.vagrant
directory in the current directory, using no specified base image.
NOTE: Before you can do avagrant up
, you'll need to specify a base image in theVagrantfile
.vagrant init <boxpath>
-- Initialise Vagrant with a specific box. For example:$ vagrant init ubuntu/trusty64
To find a box, visit the public Vagrant box catalog.
Starting/Stopping a VM
vagrant up
-- starts vagrant environment (also provisions only on the FIRST vagrant up)vagrant resume
-- resume a suspended machine (vagrant up works just fine for this as well)vagrant halt
-- stops the vagrant machinevagrant suspend
-- suspends a virtual machine (remembers state)vagrant provision
-- forces reprovisioning of the vagrant machinevagrant reload
-- restarts vagrant machine, loads new Vagrantfile configurationvagrant reload --provision
-- restart the virtual machine and force provisioning
Accessing a VM
vagrant ssh
-- connects to machine via SSHvagrant ssh <boxname>
-- If you give your box a name in yourVagrantfile
, you canssh
into it with boxname.
Removing a VM
vagrant destroy
-- stops and deletes all traces of the vagrant machinevagrant destroy -f
-- stops and deletes all traces of the vagrant machine without confirmation
Snapshots
vagrant snapshot save [options] [vm-name] <name>
-- Allows us to save so that we can rollback at a later time
VM Boxes
vagrant box list
-- see a list of all installed boxes on your computervagrant box add <name> <url>
-- download a box image to your computervagrant box outdated
-- check for updates vagrant box updatevagrant boxes remove <name>
-- deletes a box from the machinevagrant package
-- packages a running virtualbox env in a reusable box
Tips
vagrant -v
-- get the vagrant versionvagrant status
-- outputs status of the vagrant machinevagrant global-status
-- outputs status of all vagrant machinesvagrant global-status --prune
-- same as above, but prunes invalid entriesvagrant provision --debug
-- use the debug flag to increase the verbosity of the outputvagrant push
-- Vagrant can be configured to deploy code. More information on using is available http://docs.vagrantup.com/v2/push/index.htmlvagrant up --provision | tee provision.log
-- Runsvagrant up
, forces provisioning and logs all output to a file
Be the first to comment.
Leave a response