» Basic Usage
» Configuration
Synced folders are configured within your Vagrantfile using theconfig.vm.synced_folder
method. Usage of the configuration directiveis very simple:
Vagrant.configure("2") do |config|
# other config here
config.vm.synced_folder "src/", "/srv/website"
end
The first parameter is a path to a directory on the host machine. Ifthe path is relative, it is relative to the project root. The secondparameter must be an absolute path of where to share the folder withinthe guest machine. This folder will be created (recursively, if it must)if it does not exist. By default, Vagrant mounts the synced folders withthe owner/group set to the SSH user and any parent folders set to root.
» Options
You may also specify additional optional parameters when configuringsynced folders. These options are listed below. More detailed examples of usingsome of these options are shown below this section, note the owner/group examplesupplies two additional options separated by commas.
In addition to these options, the specific synced folder type mightallow more options. See the documentation for your specific synced foldertype for more details. The built-in synced folder types are documentedin other pages available in the navigation for these docs.
create
(boolean) - If true, the host path will be created if itdoes not exist. Defaults to false.disabled
(boolean) - If true, this synced folder will be disabled andwill not be setup. This can be used to disable a previously defined syncedfolder or to conditionally disable a definition based on some externalfactor.group
(string) - The group that will own the synced folder. By defaultthis will be the SSH user. Some synced folder types do not supportmodifying the group.mount_options
(array) - A list of additional mount options to passto themount
command.owner
(string) - The user who should be the owner of this synced folder.By default this will be the SSH user. Some synced folder types do notsupport modifying the owner.type
(string) - The type of synced folder. If this is not specified,Vagrant will automatically choose the best synced folder option for yourenvironment. Otherwise, you can specify a specific type such as "nfs".id
(string) - The name for the mount point of this synced folder in theguest machine. This shows up when you runmount
in the guest machine.
» Enabling
Synced folders are automatically setup during vagrant up
andvagrant reload
.
» Disabling
Synced folders can be disabled by adding the disabled
option toany definition:
Vagrant.configure("2") do |config|
config.vm.synced_folder "src/", "/srv/website", disabled: true
end
Disabling the default /vagrant
share can be done as follows:
config.vm.synced_folder ".", "/vagrant", disabled: true
» Modifying the Owner/Group
Sometimes it is preferable to mount folders with a different owner/group thanthe default SSH user. Keep in mind that these options will only affect thesynced folder itself. If you want to modify the owner/group of the syncedfolder's parent folders use a script. It is possible to set these options:
config.vm.synced_folder "src/", "/srv/website",
owner: "root", group: "root"
NOTE: Owner and group IDs defined within mount_options
will have precedenceover the owner
and group
options.
For example, given the following configuration:
config.vm.synced_folder ".", "/vagrant", owner: "vagrant",
group: "vagrant", mount_options: ["uid=1234", "gid=1234"]
the mounted synced folder will be owned by the user with ID 1234
and thegroup with ID 1234
. The owner
and group
options will be ignored.
» Symbolic Links
Support for symbolic links across synced folder implementations andhost/guest combinations is not consistent. Vagrant does its best tomake sure symbolic links work by configuring various hypervisors (suchas VirtualBox), but some host/guest combinations still do not workproperly. This can affect some development environments that rely onsymbolic links.
The recommendation is to make sure to test symbolic links on all thehost/guest combinations you sync folders on if this is important to you.