Vagrant CLI Reference
Before we begin: Make sure vagrant is installed in your machine and added to the path. To verify, run vagrant -v and make sure you get a version number of the vagrant version installed on your machine.
Reference: Vagrant Official Docs
- vagrant init
- Initialize a new vagrant environment by creating a new Vagrantfile if it does not already exist.
# Syntax: vagrant init [name [url]]
# name = name of the box to create i.e. config.vm.box
# url = url to download the box from
# Example:$ vagrant init my-company-box https://boxes/example.box
2. vagrant up
# Syntax: vagrant up [name|id]# name = Name of the box/machine defined in the Vagrantfile
# id = Unique identifier for any known machine found by running vagrant global-status
- By default, vagrant uses VirtualBox as a virtualization provider. This can be changed as follows: $ vagran up —provider <provider-name>
$ vagrant up --provider=docker
3. vagrant halt
- Used to shutdown the virtual machine
# Syntax: vagrant halt[name|id]
# Example:# vagrant halt -f
- The option -f will force the machine to shutdown,similar to how you unplug power from your PC if its taking ages to shut down.
4. vagrant suspend
- In simple terms , this is similar to the sleep action on your PC.
# Syntax: vagrant suspend [name|id]# Resume the machine to the previous state by running:
$ vagrant resume
5. vagrant destroy
- Removes all the resources consumed when bringing up the current box
- Similar to Reset To Factory Defaults on modern PCs.
- Note that this does not remove the actual box from the host machine
# Syntax: vagrant destroy [name|id]
6. vagrant global-status
- Shows information about all vagrant environments on your host machine
7. vagrant ssh
# Syntax: vagrant ssh [name|id] [-- extra_ssh_args]
# If not name or id is specified vagrant will use the default vagrant machine currently running
# e.g. vagrant ssh is equivalent to vagrant ssh default
8. vagrant port
- List all port mappings between the current virtual machine and the host machine
# Syntax: vagrant port [name|id]
9. vagrant package
- This command packages your box into a re-usable box that can be shared with other developers
# Syntax: vagrant package [name|id]
10. vagrant reload
- Typically run after configuration changes are made to the Vagrant file.
- It is essentially the same as running vagrant halt followed by vagrant up.
If at any point you are unsure how to use any vagrant command you can use the built in CLI help option as follows.
// Syntax: vagrant <command-name> -h// Example:
$ vagrant up -h
To be continued…