我使用jhcook/osx-elcapitan-10.11作为基本框。我想要一个共享的/vagrant
目录,但它“无效”,因为guest虚拟机添加不会安装在OSX中,因此/vagrant
目录无法安装。我被告知有一个workaround,那就是使用NFS。但是,需要在主机上配置它,并且可以在Vagrantfile中添加一个条目。
如果您使用的是VirtualBox提供商,则还需要确保拥有private network set up。这是由于VirtualBox的内置网络的限制。使用VMware,您不需要这个。
我正在使用VirtualBox。
再次引用documentation:
使用专用网络的最简单方法是允许通过DHCP分配IP。
Vagrant.configure("2") do |config|
config.vm.network "private_network", type: "dhcp"
end
然后回到设置“nfs”
要启用NFS,只需在同步文件夹中添加类型:“nfs”标志:
Vagrant.configure("2") do |config|
# ...
config.vm.synced_folder ".", "/vagrant", type: "nfs"
end
但它不起作用。以下是我的Vagrantfile
。另请注意,我也遇到有关USB无法正常工作的错误,解决方法是在this tutorial之后禁用USB。
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
.
.
.
Vagrant.configure("2") do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "jhcook/osx-elcapitan-10.11"
# private network setup
config.vm.network "private_network", type: "dhcp"
# enable NFS
config.vm.synced_folder ".", "/vagrant", type: "nfs"
# disable usb
config.vm.provider "virtualbox" do |vb|
# VM Customizations go here
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
end
.
.
.
end
答案 0 :(得分:1)
根据issue,解决方案是使用静态IP。根据{{3}}:
您还可以为机器指定静态IP地址。这使您可以使用静态的已知IP访问Vagrant受管计算机。静态IP的Vagrantfile如下所示:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
所以现在我的工作Vagrantfile
看起来像是:
# -*- mode: ruby -*-
# vi: set ft=ruby :
.
.
.
Vagrant.configure("2") do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "jhcook/osx-elcapitan-10.11"
# private network setup
# config.vm.network "private_network", type: "dhcp"
config.vm.network :private_network, ip: "192.168.10.2"
# enable NFS
config.vm.synced_folder ".", "/vagrant", type: "nfs"
# disable usb
config.vm.provider "virtualbox" do |vb|
# VM Customizations go here
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
end
.
.
.
end
woot woot:)
osx-el-capitan ❯ ls
Vagrantfile
osx-el-capitan ❯ echo "Hello world?" > hello-world
osx-el-capitan ❯ vagrant ssh
Last login: Tue Sep 6 09:49:21 2016 from 10.0.2.2
This-MacBook-Pro:~ vagrant$ cat /vagrant/hello-world
Hello world?
This-MacBook-Pro:~ vagrant$ echo ":)"
:)
This-MacBook-Pro:~ vagrant$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=2b<RXCSUM,TXCSUM,VLAN_HWTAGGING,TSO4>
ether 08:00:27:d2:a9:5f
inet6 fe80::a00:27ff:fed2:a95f%en0 prefixlen 64 scopeid 0x4
inet 10.0.2.15 netmask 0xffffff00 broadcast 10.0.2.255
nd6 options=1<PERFORMNUD>
media: autoselect (1000baseT <full-duplex>)
status: active
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=2b<RXCSUM,TXCSUM,VLAN_HWTAGGING,TSO4>
ether 08:00:27:76:d5:29
inet6 fe80::a00:27ff:fe76:d529%en1 prefixlen 64 scopeid 0x5
inet 192.168.10.2 netmask 0xffffff00 broadcast 192.168.10.255
nd6 options=1<PERFORMNUD>
media: autoselect (1000baseT <full-duplex>)
status: active