Catalog / Vagrant Cheatsheet
Vagrant Cheatsheet
A quick reference guide for Vagrant, covering essential commands, configuration options, and best practices for managing virtual development environments.
Vagrant Essentials
Basic Commands
|
Initializes a new Vagrant environment by creating a |
|
Starts the Vagrant environment. Downloads the specified box (if not already present) and provisions the virtual machine. |
|
Connects to the Vagrant environment via SSH. |
|
Stops the Vagrant environment gracefully. |
|
Pauses the Vagrant environment, saving its current state. |
|
Resumes a suspended Vagrant environment. |
|
Stops and deletes all traces of the Vagrant environment. |
|
Displays the current status of the Vagrant environment. |
Vagrantfile Configuration
The Example:
|
|
|
|
Networking and Provisioning
Networking Options
|
Forwards a port from the host machine to the guest machine. Example:
|
|
Creates a private network accessible only from the host machine. Example:
|
|
Creates a network bridged to your host’s network interface, making the VM accessible from the external network. Example:
|
Provisioning Methods
Vagrant can provision the VM using shell scripts, Chef, Puppet, Ansible, or Docker. Shell Provisioning Example:
|
Ansible Provisioning Example:
|
Advanced Configuration
Box Management
|
Lists all installed boxes. |
|
Adds a box from a URL or local file. |
|
Removes a box from the system. |
|
Updates installed boxes to the latest version. |
Synced Folders
Synced folders allow you to share files between your host machine and the Vagrant environment. Example:
|
The first argument is the path on the host machine, and the second argument is the path on the guest machine. |
Multi-Machine Environments
Defining Multiple Machines
Vagrant supports defining multiple machines in a single Example:
|
In this example, we define two machines: |
Managing Multiple Machines
|
Starts a specific machine. |
|
Stops a specific machine. |
|
Connects to a specific machine via SSH. |
|
Destroys a specific machine. |
|
Shows the status of all machines defined in the Vagrantfile. |