Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant and Docker not playing nice

Update: I have uninstalled both Vagrant and Docker, and will accept any answer that helps me re-install both of them in such a way that:

  1. I can run Vagrant without any dependency on Docker whatsoever; and
  2. I can run Docker without any dependency on Vagrant whatsoever; and
  3. I can run Vagrant and use Docker as the backing provider

If you look at the Vagrant source code, you'll see that my error comes from this line of code, which, for VirtualBox providers, comes from this usable method raising an error. That usable method raises an error if it thinks that VirtualBox has an invalid version (VirtualBoxInvalidVersion) or if its not detected on the local system (VirtualBoxNotDetected).

Not being a Ruby dev, it's now getting difficult for me to figure out how Vagrant is deciding to throw either of those two errors. But I think I'm getting closer to figuring out why Docker is hosing my Vagrant/VirtualBox config.


Original question:

Mac here. A few days ago I installed Vagrant and VirtualBox like so:

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

...which got it Vagrant up and running no problem whatsoever. I was able to vagrant init hashicorp/precise32; vagrant up and everything looked like it was running perfect (hashicorp/precise32 uses VirtualBox by default).

Then last night I installed Docker, which also requires VirtualBox, and got it up and running with no problem whatsoever. I was even able to get the whalesay container examples working. So far so good.

Today I went to go play around in Vagrant, and it looks like my Docker install hosed my Vagrant/VirtualBox configuration.

Now, when I run vagrant init hashicorp/precise32 on an empty directory, and then run vagrant up, I get:

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.

So then I tried specifying the provider type, even though I shouldn't have to, just to see what happens:

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.

And just for good measure, running vagrant -v produces Vagrant 1.7.2 as output.

Any ideas what went awry and what the fix is?

like image 635
smeeb Avatar asked Aug 19 '15 02:08

smeeb


People also ask

Can I use Vagrant with Docker?

Vagrant comes with support out of the box for using Docker as a provider. This allows for your development environments to be backed by Docker containers rather than virtual machines. Additionally, it provides for a good workflow for developing Dockerfiles.

Is Vagrant better than Docker?

Vagrant allows you to isolate all the necessary resources completely. However, compared to Docker, it requires more resources initially. Compared to Vagrant, Docker wins on this criterion because it spends fewer resources, and you can create Docker images faster than Vagrant virtual machines.

Why is Docker better than Vagrant?

The important difference between Vagrant vs. Docker is that Docker is used to create and run Linux containers, while Vagrant does the work to provision a machine with an operating system, a Docker installation and any other application that needs to run on the OS.

Should I use Vagrant or Docker for creating an isolated environment?

Docker is a more realistic option in most cases because of its flexibility, strong accessibility, and it's potential for all scale of projects, and even minimal resource consumption. However, for security-based projects, it's better to go with Vagrant and Virtual Machines.


1 Answers

Vagrant cares about case (at least Vagrant 1.8.1 does), so use lower case for the provider name:

vagrant up --provider=virtualbox

I think the 1.8.1 error message is much more helpful:

$ 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

You may also be able to set a default provider in your Vagrantfile.

like image 82
George P. Avatar answered Oct 04 '22 11:10

George P.