Getting Started with Vagrant for Local Development: Lesson 8 of 20

Boxes (vm.box): The Base Operating System

Up Next

Providers (vm.provider): Where the Box / OS Lives

Autoplaying in 7 seconds!

Cancel

Boxes (vm.box): The Base Operating System

The "Box"

You can see that the box being set in the configuration is the one we called during vagrant init hashicorp/precise64

    # This is the box we asked it to use for the boilerplate
    config.vm.box = "hashicorp/precise64"
end

Boxes follow this URL format and are usually hosted on Vagrant Cloud. So:

  • owner / box_name

Vagrant Cloud is the creators of Vagrant (Hahsicorp)'s storage spot for Vagrant.

Table of Contents

    There's pretty much a box for every operating system. So if you don't like Ubuntu, that's fine use Debian or CentOS. It's completely up to you.

    Quick note: You can also publish your own public or boxes here too.

    Commands

    There's a ton of commands you can use to make Vagrant talk to the box. For a full list see the Official Docs.

    I'll go over the only ones that really matter for getting started. Just remember, you run these from the folder that your Vagrantfile is located.

    vagrant up

    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

    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.

    vagrant halt

    vagrant halt Use this command to literally turn off your machine.

    vagrant destroy

    vagrant destroy This permanently removes the virtual environment from your machine.

    vagrant provision

    vagrant provision simply reruns the provisioning stuff from the Vagrantfile. We'll cover this more later.

    vagrant reload

    vagrant reload reboots your box. Doing vagrant reload --provision will just reboot your box with the provision flag saying to rerun the stuff from the Vagrantfile.

    vagrant ssh

    vagrant ssh will automatically SSH you into the box.

    vagrant ssh-config

    vagrant ssh-config This lets you see the detailed login credentials of how you could connect to the box if you wanted to some other way.

    Suspend, Halt, Destroy

    It's important to know the difference between these. So:

    • Suspend: Freezes it in current state
    • Halt: Turns it off
    • Destroy: Turns it off and deletes it

    You typically will only vagrant destroy when you are completely done and need to free up the space.

    You will do vagrant suspend or vagrant halt when you want to come back later. The "state" of your box is saved. So any changes to it will still be there (e.g.: a database).