Catalog / Vagrant Cheatsheet
Vagrant Cheatsheet
A comprehensive cheat sheet for Vagrant, covering essential commands, Vagrantfile configuration, and best practices to streamline your virtual environment development.
Getting Started with Vagrant
Installation and Setup
Install Vagrant:
|
Verify Installation:
|
Install VirtualBox (if not already installed): Vagrant relies on a provider like VirtualBox or VMware. VirtualBox is a common open-source option.
|
Basic Vagrant Commands
|
Initializes a new Vagrant environment by creating a Example: |
|
Starts the Vagrant virtual machine. It reads the Example: |
|
Connects to the Vagrant virtual machine via SSH. Example: |
|
Stops the running Vagrant virtual machine gracefully. Example: |
|
Suspends the Vagrant virtual machine, saving its current state to disk. Example: |
|
Resumes a suspended Vagrant virtual machine. Example: |
Adding a Box
Adding a box is how Vagrant knows what OS template to use. Official boxes can be found on HashiCorp’s Atlas.
Example: |
Vagrantfile Configuration
Vagrantfile Basics
The |
Basic
|
Networking
Port Forwarding |
Forwards a port from the host machine to the guest machine.
|
Private Network (Static IP) |
Configures a static IP address for the guest machine on a private network.
|
Public Network (Bridged) |
Bridges the guest machine to your host’s network, giving it an IP address on your local network.
|
Provisioning
Shell Provisioning |
Runs a shell script to automate the setup of the guest machine.
|
Ansible Provisioning |
Uses Ansible to provision the guest machine.
|
Puppet Provisioning |
Uses Puppet to provision the guest machine.
|
Advanced Vagrant Features
Synced Folders
Synced folders allow you to share files between your host machine and the Vagrant guest machine. By default, the Vagrantfile directory is synced to |
Configuring synced folders:
|
NFS Synced Folders: For better performance, especially on macOS, you can use NFS synced folders.
|
Multiple Machines
Vagrant allows you to define and manage multiple virtual machines within a single |
Defining multiple machines:
|
Accessing specific machines:
|
Box Management
|
Lists all installed boxes. Example: |
|
Removes a specified box from your system. Example: |
|
Checks for updates for installed boxes and installs them. Example: |
Troubleshooting and Tips
Common Issues
Networking Conflicts: |
Provider Issues: |
Synced Folder Permissions: |
Vagrant Plugins
|
Installs a Vagrant plugin. Example: |
|
Lists installed Vagrant plugins. Example: |
|
Uninstalls a Vagrant plugin. Example: |
Tips and Tricks
Use a Version Control System: |
Customize Guest Machine Hostname:
|
Optimize Performance: |