I have a vagrant VM and I have shared a folder (my code repo) from the host (Ubuntu) to vagrant using config.vm.share_folder
. I would like to do the opposite with a folder I have created inside the vagrant machine (a virtual environment) I would like to share it back to the host. How can I do that?
I have tried to add the following to the vagrant file: config.vm.share_folder "virtualenv", "/home/vagrant/devenv", "../virtualenv"
which points respectively to the virtual environment on the vagrant machine and to an empty folder on the host. When I vagrant up and look inside the folder on the host I would like to see the content of the virtual env inside the vagrant machine but the folder stays empty. And when I ssh into the vagrant machine and look inside the virtual env folder it has become empty. Deactivating this setting restores the content of the folder on the vagrant machine.
By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant directory in your guest machine.
Explore the synced folder Tip: When you vagrant ssh into your machine, you're in /home/vagrant , which is a different directory from the synced /vagrant directory. Believe it or not, the Vagrantfile that you see inside the virtual machine is actually the same Vagrantfile that is on your actual host machine.
Shared folders has been renamed to synced folders from v1 to v2 (docs), under the bonnet it is still using vboxsf
between host and guest (there is known performance issues if there are large numbers of files/directories).
NOTE: You need to understand it mounts host directory into the guest via
vboxsf
, NOT the other way around.
In your use case, you can
rsync
is preferred) or move the project into the mapped folder.scp
or rsync
) folder
A, and then use synced folder to map folder A on host into guest.For example
# relative path to where Vagrantfile resides
config.vm.synced_folder "virtualenv", "/home/vagrant/devenv"
# absolute path
config.vm.synced_folder "/path/to/virtualenv", "/home/vagrant/devenv"
maps the virtualenv directory in the project directory (where the Vagrantfile
resides) to guest /home/vagrant/devenv
.
absolute path
More information that can help you understand how synced folders work =>
Vagrant shared and synced folders
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With