Skip to content

Instantly share code, notes, and snippets.

@dharma017
Last active November 22, 2015 10:16
Show Gist options
  • Select an option

  • Save dharma017/30debbbbc0d72127ddfe to your computer and use it in GitHub Desktop.

Select an option

Save dharma017/30debbbbc0d72127ddfe to your computer and use it in GitHub Desktop.
Vagrant Up and Running

Vagrant Up and Running

$mkdir vagrant_www/www -p

$cd vagrant_www

$echo "<h1>Hello from a Vagrant VM</h1>" > www/index.html

$vagrant init

$vagrant box add precise64 http://files.vagrantup.com/precise64.box

$vagrant up

$vagrant ssh

$cd /vagrant

$sudo python -m SimpleHTTPServer 80

In host browser: http://localhost:8080

$vagrant suspend
$vagrant status
$vagrant up 

OR

$vagrant resume

Note:

up:- this will do proper boot sequence depending on state of machine, even if it isn't suspended

resume:- will show an error if machine isn't suspended

To shutdown like normal pc when restarted using vagrant up, may need to start webservice again

$vagrant halt --force   

destroy VM and associated drives

$vagrant destroy --force

Recreate Vagrant Environment

$vagrant up

$vagrant ssh

$sudo apt-get udpate

$sudo apt-get install apache2 -y

$sudo rm -rf /var/www

> change `/var/www` to be a symbolic link to the default shared folder
$sudo ln -s /vagrant /var/www   

$logout

$echo "<strong>Hello!</strong>" > index.html

Reload if Vagrant Modified

$vagrant reload

$vagrant ssh

%free -m

Package Vagrant Environment

Version 1

$vagrant package --output vagrant_example.box

Version 2

When you package a box, the box name has to be the specific machine name that you can get from VirtualBox (e.g. lucid_1372711888). Just execute following command in cmd:

vboxmanage list vms

Notice that "vboxmanage" should prior be added to PATH variable. See here how to do that.

Also notice that virtual maschine name must not contain spaces. Otherwise it won't be recognized by "vagrant package" command. For instance:

vagrant package --base scotch-box_default_1444817558360_40202

Shutting down all VirtualBox (vagrant) VMs

vboxmanage list runningvms | sed -r 's/.*\{(.*)\}/\1/' | xargs -L1 -I {} VBoxManage controlvm {} savestate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment