我可以在 Vagrant 中安装共享文件夹之前强制进行配置吗?

Can I force provisioning to happen before mounting shared folders in Vagrant?

我有以下 Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/6"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network :forwarded_port, host: 8080, guest: 80
  config.vm.network :forwarded_port, host: 3306, guest: 3306
  config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"

  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", 2048]
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      vb.name = "appserver"
   end
end

每次我运行vagrant up(第一次,比方说我先运行vagrant destroy -f),我都会遇到以下错误:

==> default: Mounting shared folders...
    default: /vagrant => E:/Development/vagrant/centos6
    default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

id -u apache    
The error output from the command was:    
id: apache: No such user

错误很明显"apache user does not exists"。正如我所见,有两种或 "three" 方法可以解决此问题:

有人知道这是否可行吗?如果可行的话如何?我找不到关于第三个解决方案的任何信息:( 如果您有更好的解决方案,非常欢迎您来到 post 此处,它可能对我和其他人有帮助。

我找到了 this and this 但没有帮助。

一个可能的解决方案是 运行 apache 作为 vagrant 用户。

在您的 /etc/httpd/conf 中,您可以将用户和群组值替换为

User vagrant
Group vagrant

因此您可以继续与 vagrant 用户共享您的文件夹,httpd 将 运行 作为 vagrant 用户。

您可以使用数字 ID,然后创建用户

config.vm.synced_folder '${HOSTDIR}', '${EXPORTDIR}', type: "virtualbox", owner: '123', group: '456'
config.vm.provision :shell, inline: "useradd --system -g '456' -u '123' -d '${EXPORTDIR}' --shell /bin/false apache"