62

次の内容の Vagrantfile を作成しました。

Vagrant::Config.run do |config|

  config.vm.define :foo do |cfg|
    cfg.vm.box     = 'foo'
    cfg.vm.host_name = "foo.localdomain.local"
    cfg.vm.network :hostonly, "192.168.123.10"
  end

  Vagrant.configure("2") do |cfg|
    cfg.vm.customize [ "modifyvm", :id , "--name", "foo" , "--memory", "2048", "--cpus", "1"]
    cfg.vm.synced_folder "/tmp/", "/tmp/src/"
  end

end

vagrant upまたはvagrant reload私が得る:

[foo] Attempting graceful shutdown of VM...
[foo] Setting the name of the VM...
[foo] Clearing any previously set forwarded ports...
[foo] Fixed port collision for 22 => 2222. Now on port 2200.
[foo] Creating shared folders metadata...
[foo] Clearing any previously set network interfaces...
[foo] Preparing network interfaces based on configuration...
[foo] Forwarding ports...
[foo] -- 22 => 2200 (adapter 1)
[foo] Booting VM...
[foo] Waiting for VM to boot. This can take a few minutes.
[foo] VM booted and ready for use!
[foo] Setting hostname...
[foo] Configuring and enabling network interfaces...
[foo] Mounting shared folders...
[foo] -- /vagrant

私の質問は次のとおりです。

  1. Vagrant が/vagrant共有フォルダーをマウントするのはなぜですか? 同期されたフォルダーを支持して共有フォルダーが非推奨になっていることを読みましたが、Vagrantfile で共有フォルダーを定義したことはありません。
  2. 同期フォルダが設定されていないのはなぜですか?

MacOX 10.8.4 で Vagrant バージョン 1.2.7 を使用しています。

4

1 に答える 1

109

共有フォルダー VS 同期フォルダー

基本的に、共有フォルダーは v1 から v2 (ドキュメント) への同期フォルダーに名前が変更され、vboxsfホストとゲストの間でまだ使用されているボンネットの下にあります (多数のファイル/ディレクトリがある場合、既知のパフォーマンスの問題があります)。

/vagrantゲストとしてマウントされた Vagrantfile ディレクトリ

Vagrant は、ゲストとVagrantfile同様に現在の作業ディレクトリ (存在する場所) をマウントし/vagrantます。これがデフォルトの動作です。

ドキュメントを見る

注: デフォルトでは、Vagrant はプロジェクト ディレクトリ (Vagrantfile のあるディレクトリ) を /vagrant に共有します。

を追加することで、この動作を無効にすることができcfg.vm.synced_folder ".", "/vagrant", disabled: trueますVagrantfile

同期フォルダが機能しない理由

/tmpホストの出力に基づいて、アップタイム中にマウントされませんでした。

VAGRANT_INFO=debug vagrant upまたはを使用VAGRANT_INFO=debug vagrant reloadして VM を起動し、同期されたフォルダーがマウントされていない理由に関する詳細な出力を確認します。許可の問題である可能性があります (/tmpホストのモード ビットは である必要がありますdrwxrwxrwt)。

以下を使用してテストクイックテストを実行しましたが、うまくいきました(opscode Bento raring vagrant base boxを使用しました)

config.vm.synced_folder "/tmp", "/tmp/src"

出力

$ vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Available bridged network interfaces:
1) eth0
2) vmnet8
3) lxcbr0
4) vmnet1
What interface should the network bridge to? 1
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/src

VM 内で、マウント情報を確認できます/tmp/src on /tmp/src type vboxsf (uid=900,gid=900,rw)

于 2013-08-30T09:38:21.930 に答える