我开始了一个新的Vagrant项目来学习一些Django。 VM运行良好,一切正常,但我不知道如何使用像Sublime这样的文本编辑器访问VM中的文件进行编辑。
在VM上cd / vagrant进入我的Desktop Vagrant文件夹。但是,我无法找到我的VM主目录文件夹存储在主机上的位置。
/流浪
-Vagrantfile
-cookbooks
--apache2
--apt
--build-essential
--git
--vim
〜$
-build
-django_project
--django_project
--manage.py
-postinstall.sh
答案 0 :(得分:1)
您的访客的主目录未共享,您需要在Vagrantfile
中手动设置。
修改强>
查看该文件的内部并取消注释该行(阅读该行上方的注释以获取更多详细信息):
# config.vm.synced_folder "../data", "/vagrant_data"
答案 1 :(得分:1)
您可以共享任何您想要的文件夹。您只需要在Vagrantfile文件中说出要与猜测分享的文件夹
在这种情况下,我创建了一个名为 data 的文件夹,因为默认情况下这个文件夹不存在。这是我的项目结构。数据文件夹和Vagrantfile位于同一目录级别。
.
├── attributes
├── Berksfile
├── Berksfile.lock
├── chefignore
├── **data**
│ └── **hello**
├── definitions
├── files
│ └── default
├── Gemfile
├── Gemfile.lock
├── libraries
├── LICENSE
├── metadata.rb
├── providers
├── README.md
├── recipes
│ ├── default.rb
│ └── gem_sources.rb
├── resources
├── templates
│ └── default
├── test
│ └── integration
│ └── default
├── Thorfile
└── **Vagrantfile**
这是Vagrantfile文件配置。
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
config.vm.hostname = "ubuntu"
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu-12.04"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "data", "/vagrant_data"
end
数据文件夹中的所有内容都可以在guess中的vagrant_data文件夹中访问。你可以看到你好文件。
roberto@rcisla-pc:~/Desktop/stack$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Sun Jan 19 13:20:49 2014 from 10.0.2.2
vagrant@ubuntu:~$ cd /vagrant_data/
vagrant@ubuntu:/vagrant_data$ ls
hello
vagrant@ubuntu:/vagrant_data$
我希望这对你有所帮助。 对不起我的英文