Vagrant 配置错误 - "A box must be specified."

Vagrant Config Error - "A box must be specified."

这些盒子工作正常。然后我停止了一个(当时唯一的一个 运行),现在我无法恢复它们中的任何一个。


运行 vagrant up [name] 给我以下错误,无论我选择哪个或者我是否将其留在 vagrant up 让他们都出现:

There are errors in the configuration of this machine. Please fix
the following errors and try again:

vm:
* A box must be specified.

运行 最新版本的 Vagrant (1.7.4)。

这是我的完整 Vagrantfile,包括评论(以防万一):

# Search for boxes here: https://atlas.hashicorp.com/boxes/search
# Refer to commands_vagrant.txt for command reference

Vagrant.configure("2") do |config|

    # Globally defined variables
    config.vm.synced_folder "./", "/var/www/public"

    # CentOS 6.5, Apache 2.2.15, MySQL 5.5.36 (-u root), PHP 5.3.28
    # Note: If PHP session keys don't work, set permissions to 777 (or other more restrictive, but this is guaranteed to work) on /var/lib/php/session
    config.vm.define "php5dot3", primary: true do |php5dot3|
        config.vm.box = "smallhadroncollider/centos-6.5-lamp"
        config.vm.network :forwarded_port, guest: 80, host: 4567
    end

    # Ubuntu 14.04 (SSH pw: vagrant), Apache 2.4.12, MySQL 5.5.43 (-u root -p root), PHP 5.6.10
    config.vm.define "php5dot6" do |php5dot6|
        config.vm.box = "scotch/box"
        config.vm.network :forwarded_port, guest: 80, host: 4568
    end

end

运行vagrant status的结果:

Current machine states:

php5dot3                  poweroff (virtualbox)
php5dot6                  poweroff (virtualbox)

运行vagrant global-status的结果:

id       name     provider   state    directory                           
--------------------------------------------------------------------------
e1f3c85  default  virtualbox poweroff /home/sam/Web                       
c588d51  php5dot6 virtualbox poweroff /home/sam/Web                       
4e71c50  php5dot3 virtualbox poweroff /home/sam/Web    

'default' 是我上周让多台机器工作之前在我的 Vagrantfile 中的唯一框。 (相关?)


运行vagrant box list的结果:

scotch/box                          (virtualbox, 2.0)
smallhadroncollider/centos-6.5-lamp (virtualbox, 1.0.0)

如有任何帮助,我们将不胜感激。

在您的机器定义中,您需要使用该机器的变量名称,而不是 config。试试这个:

在下面的文件中,我已将 config.vm 更改为 php5dot3.vmphp5dot6.vm:

Vagrant.configure("2") do |config|

    # Globally defined variables
    config.vm.synced_folder "./", "/var/www/public"

    # CentOS 6.5, Apache 2.2.15, MySQL 5.5.36 (-u root), PHP 5.3.28
    # Note: If PHP session keys don't work, set permissions to 777 (or other more restrictive, but this is guaranteed to work) on /var/lib/php/session
    config.vm.define "php5dot3", primary: true do |php5dot3|
        php5dot3.vm.box = "smallhadroncollider/centos-6.5-lamp"
        php5dot3.vm.network :forwarded_port, guest: 80, host: 4567
    end

    # Ubuntu 14.04 (SSH pw: vagrant), Apache 2.4.12, MySQL 5.5.43 (-u root -p root), PHP 5.6.10
    config.vm.define "php5dot6", autostart:false do |php5dot6|
        php5dot6.vm.box = "scotch/box"
        php5dot6.vm.network :forwarded_port, guest: 80, host: 4568
    end

end

我还在 php5dot6 框的定义中添加了 autostart:false,如果您愿意,可以将其删除。 (这只是意味着 运行 vagrant up 默认情况下只会启动主。

如果您在使用 DigitalOcean 时遇到此错误,您可能需要他们的插件:

vagrant plugin install vagrant-digitalocean
Installing the 'vagrant-digitalocean' plugin. This can take a few minutes...
Fetching: multipart-post-2.0.0.gem (100%)
Fetching: faraday-0.15.4.gem (100%)
Fetching: vagrant-digitalocean-0.9.3.gem (100%)

对于现在遇到此问题的人:

我在尝试销毁 Vagrantfile 之前删除了它。您需要从该进程的 Vagrantfile 所在的正确目录中 运行 vagrant destroy 命令。

运行 vagrant ssh-config 然后查看目录栏。

如果您像我一样删除了文件,请执行以下操作:

vagrant init

然后

vagrant destroy $id

P.S.: 如果您有权限问题,请使用 sudo 运行 使用这些命令。