-
Notifications
You must be signed in to change notification settings - Fork 138
Vagrant Tips and Tricks
Vagrant has many commands to control its virtual machine. For a full list, see the official docs here, but here are the most common:
vagrant up
This is the command you just ran to boot the box up and provision the server based on the configuration file Vagrantfile. I use this for starting as well as resuming my environments.
vagrant suspend
Use this command to “pause” your virtual environment. Make sure you do this before shutting down your computer to safely be able to restore the environment later.
Starting, Pausing, and Resuming: To start or restore the environment you can just run vagrant up
. The state will be saved and everything should be where you left it off from including your database changes.
vagrant destroy
This permanently removes the virtual environment from your machine.
vagrant reload
If your environment suddenly stops working, it’s useful to reboot by running this command. If you add the --provision flag, it will re-provision the box as well.
vagrant ssh
If you need to connect to the virtual server, just run this command.
In the Vagrantfile, this line specifies how much memory is allocated to the Virtual Machine:
v.customize ["modifyvm", :id, "--memory", "4096"]
If you want to use VMWare Fusion instead of VirtualBox, use vagrant up --provider=vmware_fusion
instead of vagrant up
when building the VM for the first time. After that, Vagrant will remember your provider choice, and you won't need to include the provider flag again.
In the Vagrantfile, uncomment the following line:
#v.gui = true
Edit pg_hba.conf
in the Vagrant VM to allow the host machine access. This command uses Vim, but any text
editor will work:
vim /etc/postgresql/9.1/main/pg_hba.conf
Add an entry to allow access to the database:
host all all 0.0.0.0/0 trust
The server IP address for the Vagrant database will be the static private IP address of the Virtual Machine: 192.168.33.10