Learn Vagrant from Scratch : Syncing local folder to the virtual machine

Learn Vagrant from Scratch : Syncing local folder to the virtual machine
Rate this post

Synced folder are awesome for developers as you will not always want to edit the project, in such case sync the folder edit in your favorite editor and see the results on your vagrant box.

Synced folders are configured within your Vagrantfile using the

config.vm.synced_folder method present in Vagrant setting.

By default vagrant treat root directory as synced folder. To change this to your desired directory follow the below steps.

Vagrant.configure("2") do |config|
  # other config here

  config.vm.synced_folder "src/", "/src/website"
end

The first parameter to is a path to config.vm.synced_folder is a directory on local. If the path is relative, it is relative to the project root. The second parameter must be an absolute path of where to share the folder in virtual machine. This directory and subdirectory will be created if it does not exist.

Now that you have applied the settings. If you are running

vagrant up

settings will automatically be migrated also you have to do

vagrant reload

to apply the settings you have changed. There are other options present for configuring you can learn about them here.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.