Basic
Usage
- One of the most useful senario with Vagrant is to setup a network of serveral computing nodes to mimic a distributed system. Or even better, use Docker.
Preparation
Download offline file for instable network, esp. in case u r behind the “greatwall”:
Search the box in https://atlas.hashicorp.com/ for box name, version, then follow the format
https://atlas.hashicorp.com/puppetlabs/boxes/<boxName>/versions/<version>/providers/virtualbox.box
to construct the downloading url. e.g. https://atlas.hashicorp.com/puppetlabs/boxes/centos-7.0-64-puppet/versions/1.0.2/providers/virtualbox.box
Change the Storage Location
- Press
Win+R
and typesystempropertiesadvanced
to bring up the “System Properties” dialog, click “Environment Variables…” button, and in the “User vairalbes for $USER” section, add a variable namedVAGRANT_HOME
, whose value isD:\your\vagrant\working\path
.
Or use the command line:
SETX VAGRANT_HOME "D:\your\vagrant\working\path"
- Change VirtualBox storage location: Open Virtalbox and navigate to
File > Preference> General: Default Machine Folder
: change to target location.
Setup Vagrant Virtual Machine
Execute below commands in cmder/cmd.exe:
echo check vagrant_home: %vagrant_home%
set BN=boot2docker-virtualbox
set BOXPATH=D:\tools\vagrant-boxes\boot2docker-virtualbox.box
cd /d D:\HashiCorp\Vagrant\myvagrantfile
mkdir %BN%
cd %BN%
vagrant box add %BN% %BOXPATH%
vagrant box list
vagrant init %BN%
And issue command vagrant up && vagrant ssh
to startup and connect to the vagrant vm and install the dev tools manually, then key in vagrant package --output my-dev.box
to export the whole box as a file which can then be shared b/w team members to setup the same dev env quickly.
(If you are using cmder full version, the ssh
command is right in your hands, so simply type vagrant ssh
to connect to the vagrant box; otherwise, use a ssh client, say Putty, MobaXterm.)
Or edit the Vagrantfile
file to setup the dev env in script.
Troubleshooting
If both host-only network and shared folder are enabled in Vagrantfile:
config.vm.network "private_network", ip: "192.168.33.15"
config.vm.synced_folder "e:", "/host_e"
The host-only network is accessible, but the synced_folder cannot be found! (I don’t know whether this bug is in Vagrant, or reproducible only in my machine)
Solution: create the /host_e
directionary, then mount the drive in ~/.bashrc
file manually:
echo 'sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) host_e /host_e' >> ~/.bashrc