【问题标题】:Vagrant and Docker not playing niceVagrant 和 Docker 玩得不好
【发布时间】:2015-08-19 02:02:21
【问题描述】:

更新:我已经卸载了 Vagrant 和 Docker,并将接受任何有助于我重新安装它们的答案:

  1. 我可以在不依赖 Docker 的情况下运行 Vagrant;和
  2. 我可以在不依赖 Vagrant 的情况下运行 Docker;和
  3. 我可以运行 Vagrant 并使用 Docker 作为支持提供程序

如果您查看 Vagrant 源代码,您会发现我的错误来自 this line of code,而对于 VirtualBox 提供者来说,它来自 this usable method 引发错误。如果 usable 方法认为 VirtualBox 的版本无效 (VirtualBoxInvalidVersion) 或在本地系统上未检测到 (VirtualBoxNotDetected),则会引发错误。

不是 Ruby 开发人员,我现在很难弄清楚 Vagrant 是如何决定抛出这两个错误中的任何一个。但我认为我越来越接近于弄清楚为什么 Docker 会占用我的 Vagrant/VirtualBox 配置。


原问题:

这里是 Mac。几天前我像这样安装了Vagrant 和VirtualBox:

brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager

...它让它 Vagrant 启动并运行没有任何问题。我可以vagrant init hashicorp/precise32; vagrant up 并且一切看起来都运行得很完美(hashicorp/precise32 默认使用 VirtualBox)。

然后昨晚我安装了Docker,它也需要VirtualBox,并且启动并运行没有任何问题。我什至能够让whalesay 容器示例正常工作。到目前为止一切顺利。

今天我去 Vagrant 玩,看起来我的 Docker 安装破坏了我的 Vagrant/VirtualBox 配置。

现在,当我在一个空目录上运行vagrant init hashicorp/precise32,然后运行vagrant up,我得到:

myuser@mymac:~/sandbox/myapp$vagrant up
No usable default provider could be found for your system.

Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.

The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.

If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.

然后我尝试指定提供程序类型,即使我不应该这样做,只是为了看看会发生什么:

myuser@mymac:~/sandbox/myapp$vagrant up --provider=VirtualBox
The provider 'VirtualBox' could not be found, but was requested to
back the machine 'cortex'. Please use a provider that exists.

为了更好地衡量,运行vagrant -v 会产生Vagrant 1.7.2 作为输出。

任何想法出了什么问题以及解决方法是什么?

【问题讨论】:

  • 我在安装 docker 工具箱后遇到了类似的问题,运行此命令后修复 rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems
  • 感谢@BMW,但这对我不起作用。
  • Ubuntu 12.04 不建议使用 docker,因为 docker 需要 Linux 内核 3.13+。虽然你可以在里面运行sudo apt-get update && sudo apt-get install linux-image-generic-lts-trusty来升级内核,但我还是建议你改用Ubuntu 14.04。
  • 好像你的virtualbox感知有问题,试试手动下载安装吧。
  • 你是如何安装 Docker 的?你用过OS X installer from the Docker site吗?也许重新安装 Vagrant,然后安装 Docker — 但这次进行自定义安装,不要安装 VirtualBox(请参阅 step 4's screenshot)。

标签: macos docker vagrant


【解决方案1】:

Vagrant 关心大小写(至少 Vagrant 1.8.1 如此),因此提供者名称使用小写:

vagrant up --provider=virtualbox

我认为 1.8.1 的错误信息更有帮助:

$ vagrant up --provider=VirtualBox  # NOTE: this is the WRONG capitalization
An active machine was found with a different provider. Vagrant
currently allows each machine to be brought up with only a single
provider at a time. A future version will remove this limitation.
Until then, please destroy the existing machine to up with a new
provider.

Machine name: default
Active provider: virtualbox
Requested provider: VirtualBox

您还可以在 Vagrantfile 中设置默认提供程序。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,并通过将 Vagrant 更新到最新版本来修复它(有 1.7.2,更新到 1.8.1)。

    【讨论】:

    • 这个 - 到目前为止,1.7.2 是博洛尼亚,现在都是 1.8.1。
    【解决方案3】:

    我得到了这个工作,但不知道实际的解决方案是什么。

    1. 卸载 Vagrant 和 Docker
    2. 手动重新安装 Vagrant(不是通过 brew/cask
    3. this link重新安装Docker
    4. 使用this Vagrantfile to confirm 让您的 Vagrant-Docker-VirtualBox 可以很好地协同工作

    【讨论】:

      【解决方案4】:

      我无法重现该问题。但是,我从 Vagrant 的 VirtualBox 提供程序中阅读了一些源代码。听起来它可能在$PATH 中找不到VBoxManage。它应该位于/usr/bin/VBoxManage,即使是通过 Homebrew 安装的。可能是您的 $PATH 变量不正确,或者 VBoxManage 在其他地方。

      其他有同样问题的读者应该:

      • 检查/etc/paths 以确保列出/usr/bin 以及通常在$PATH 中找到的所有其他目录。
      • 查找名为~/.bashrc~/.bash_profile 的文件。 Mac OS X 默认不附带这些文件,但一些用户添加它们以自定义 bash,并且一些程序可能会尝试自动编辑/创建它们。警惕任何看起来像export PATH=... 的行。在 OS X 上,应在 /etc/paths/etc/paths.d/* 中更改 $PATH,而不是在 bash 脚本中。
      • 运行type -a VBoxManage 以查看名为VBoxManage 的可执行文件的所有已知位置。某处可能有一个杂散二进制文件优先于真正的二进制文件。

      【讨论】:

        猜你喜欢
        • 2011-06-15
        • 2019-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-25
        • 2011-10-14
        • 2015-07-06
        • 2022-08-21
        相关资源
        最近更新 更多