Vagrant 错误 - 同名的 VirtualBox 机器已经存在 [英] Vagrant error - A VirtualBox machine with the name already exists

查看:31
本文介绍了Vagrant 错误 - 同名的 VirtualBox 机器已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ubuntu/xenial64 框为两个单独的项目创建两个单独的 VM.我在两个单独的项目目录中定义了 Vagrantfile,并在每个目录中添加了 config.vm.box = "ubuntu/xenial64" 行.

I want to use ubuntu/xenial64 box to create two separate VMs for two separate projects. I defined Vagrantfile in two separate project directories and added the line config.vm.box = "ubuntu/xenial64" to each.

第一个盒子启动成功.但是当我为第二个项目执行 vagrant up 时,我收到错误

The first box boots successfully. But when I do vagrant up for second project, I get the error

A VirtualBox machine with the name 'ubuntu-xenial-16.04-cloudimg' already exists.

在 Vagrant 的文档中清楚地写道

In Vagrant's documentation it's clearly written that

框为当前用户全局存储.每个项目使用一个框作为要从中克隆的初始图像,并且从不修改实际基础图像.这意味着如果您有两个项目都使用我们刚刚添加的 hashicorp/precise64 框,在一个来宾中添加文件机器对另一台机器没有影响.

Boxes are globally stored for the current user. Each project uses a box as an initial image to clone from, and never modifies the actual base image. This means that if you have two projects both using the hashicorp/precise64 box we just added, adding files in one guest machine will have no effect on the other machine.

那为什么我会收到这个错误?

Why then do I get this error?

我已经查看了其他类似问题,但我不明白他们删除看似具有相同名称的现有 VM 的解决方案.根据上面的 Vagrant 文档引用,这不是必需的.我错过了什么吗?

I have already checked out other similar questions, but I don't understand their solution of deleting existing VMs that appear to have the same name. According to the Vagrant documentation quote above, that shouldn't be necessary. Am I missing something?

推荐答案

您无需删除另一个 VM,实际上您当然可以在同一个框中拥有多个 VM.

You dont need to delete the other VM and indeed you can certainly have many VMs from the same box.

您的错误可能与在 VirtualBox 中创建的 VM 的 VirtualBox 名称有关,如果您覆盖了一个属性以在您的 2 个项目中设置此名称及其相同的名称,那么将会发生冲突,请参阅此 answer 查看定义 VM 名称的不同方式

your error might have to do with the VirtualBox Name of the VM created in VirtualBox, If you have override a property to set this name and its the same name on your 2 projects then there will be a collision, see this answer to see the different ways to define the name of the VM

所以要么让 vagrant 定义 VM 的名称,要么确保在不同的项目中有唯一的 VM 名称,它会运行得很好

so either leave vagrant define the name of the VM or make sure you have unique VM name in your different project and it will run just fine

更新我选中了这个特定的框,它包含以下 Vagrantfile

UPDATE I check this particular box and it contains the following Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.base_mac = "02101FC67BA9"
  config.ssh.username = "ubuntu"
  config.ssh.password = "c1580f876b655137c6c35b69"
  config.vm.synced_folder '.', '/vagrant', disabled: true

  config.vm.provider "virtualbox" do |vb|
     vb.name = "ubuntu-xenial-16.04-cloudimg"
     vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
     vb.customize [ "modifyvm", :id, "--uartmode1", "file", File.join(Dir.pwd, "%s-console.log" % vb.name) ]
  end
end

因此请确保在您的 Vagrantfile 中覆盖此属性

so make sure in your Vagrantfile to override this property

  config.vm.provider "virtualbox" do |vb|
     vb.name = "your specific project name"

并将 vb.name 更改为每个项目的唯一值.

and change the vb.name to be unique for each of your projects.

这篇关于Vagrant 错误 - 同名的 VirtualBox 机器已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆