Vagrant – VagrantFile

VagrantFile is in ruby syntax. This is configuration that is used when vagrant creates vms. If no directory is given vagrant will mount vagrant folder as shared folder between host and container/vm .

To setup custom sync folder

Vagrant.configure("2") do |config|
  config.vm.box = 'centos/7'
  # configures synced folder
  config.vm.synced_folder "./content", "/vagrant"
end 

To setup multi VMs in one vagrant file

Vagrant.configure("2") do |config|

  config.vm.define "web" do |web|
    web.vm.box = "centos/7"
  end

  config.vm.define "db" do |db| 
    db.vm.box = "centos/7"
  end
end

To create and start up VMs

cd to the folder you hace your VagrantFile in and run the following command:

vagrant up

These are really simple configuration files but can get complex fast with network / provider config. Virtualbox is the easiest to use. Libvirt seems to take the most tweaking especially with networks.

Leave a comment

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax