Vagrant 错误 - 同名的 VirtualBox 机器已经存在

标签 vagrant virtualbox

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

第一个盒子成功启动。但是当我做 vagrant up对于第二个项目,我得到了错误

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

在 Vagrant 的文档中清楚地写着

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.



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

我已经 checkout other similar questions ,但我不明白他们删除似乎具有相同名称的现有虚拟机的解决方案。根据上面的 Vagrant 文档引用,这不是必需的。我错过了什么吗?

最佳答案

您不需要删除其他虚拟机,实际上您当然可以从同一个盒子中拥有许多虚拟机。

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

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

更新
我选中了这个特定的框,它包含以下 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 中覆盖此属性
  config.vm.provider "virtualbox" do |vb|
     vb.name = "your specific project name"

并更改 vb.name对您的每个项目都是独一无二的。

关于Vagrant 错误 - 同名的 VirtualBox 机器已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37165846/

相关文章:

php - Windows w/Precise64 上的 Vagrant 运行 php 非常慢

linux - 无法访问 Puppet 学习虚拟机

centos - Openstack 实例 - 没有可启动设备

Windows 10 周年更新后出现 Vagrant up 错误

docker - Docker作为Vagrant的提供商

python - 在 Vagrant 中运行 Python 脚本

virtualhost - 生产中的 Vagrant

windows - Vagrant 无法与客人交流

php - Laravel:为什么数据库 Seeder 在我的快速电脑上如此慢

linux - 在虚拟机中启用 VT-x