vagrant init hashicorp/precise64
* Create a fully-functioning Ubuntu 12.04 VM.
vagrant init bento/ubuntu-16.04
* Create a fully-functioning Ubuntu 16.04 VM.
* Start a VM.
* SSH into working directory's vagrant VM.
* Terminate a running vagrant VM (see "Teardown" section later for more options).
* Can completely remove the box file with this command:
vagrant box remove
A Vagrantfile is a file that marks the root directory of project and describes the kind of machine and resources that are needed to run the project as well as what software to install and how to access it.
* Many configuration options are relative to the root directory.
* Initialize directory:
* Vagrantfile is meant to be committed to version control.
A box is a base image of a VM.
* Vagrant uses boxes to quickly clone VMs.
* Specifying the box to use is the next step after creating a new Vagrantfile.
* The commands in "Up and Running" are the ones used to install a box.
* Example of adding a box:
vagrant box add hashicorp/precise64
* Stores under a name so it can be re-used by other environments.
? I think init does this already, but I'm not positive.
* Can get boxes from websites or local files.
Can get (and host) boxes from HashiCorp's Atlas box catalog.
* "Boxes are globally stored for the current user"
? I think by this they mean one Ubuntu box is recycled for all Ubuntu projects for every user, but I'm not sure.
* Projects don't modify the actual base image.
* This means that two projects using the same base image won't conflict.
* Configure a box by modifying Vagrantfile.
* config.vm.box must match name used in "init" command or "box add" command.
* Can optionally specify version of a box with config.vm.box_version.
* Can optionally specify url.
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.box_version = "1.1.0" config.vm.box_url = "http://files.vagrantup.com/precise64.box" end
! /vagrant on the guest machine is shared with the directory containing Vagrantfile on the host machine.
Using automated provisioning, vagrant will automatically install software when the VM is started.
* Installing Apache example:
* Putting this shell script as bootstrap.sh in the same directory as Vagrantfile:
#!/usr/bin/env bash apt-get update apt-get install -y apache2 if ! [ -L /var/www ]; then rm -rf /var/www ln -fs /vagrant /var/www fi
* And editing the Vagrantfile:
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "bootstrap.sh" end
! Notice the "provision" line, which tells Vagrant what to do to set up the machine.
* In particular, it tells it to run the sh file.
vagrant reload --provision
* Can reload the already-running vm to use new provisions with:
* Particularly complex setups are probably not best done through provisioning, but with custom Vagrant boxes.
* Going to use networking features to give additional options for accessing guest machine from host machine.
Port forwarding lets you share ports on guest machine through a port on the host machine.
* So the guest machine can act as a server.
* Add to Vagrantfile configuration:
config.vm.network :forwarded_port, guest: 80, host:4567
* Can now access Apache file server from host machine via localhost:4567.
* There are other options, including bridging to an existing network.
Vagrant Share lets you share your Vagrant environment.
* I didn't really expect it to do anything different.
* Skipping details of vagrant share; not concerned about it right now.
* Saves current running state of the machine and stops it.
* Can restart with vagrant up, and will resume where left off.
* Uses up a lot of disk space.
* Will still be listed in VirtualBox list.
* Shuts down the VM.
* Can restart with vagrant up.
* Preserves contents to disk.
* Will still be listed in VirtualBox list.
* Completely removes the VM from the system-- Nothing left on disk.
* Can restart with vagrant up, but it will take longer to restart everything because it needs to be reprovisioned.
* Will no longer be listed in VirtualBox list.
! Not going beyond "Getting Started" *yet*, because think this may be enough to figure out everything else through Google. May go further in the future.
* Put this into Vagrantfile:
config.vm.network "private_network", ip: "192.168.50.4"