If your purpose is the isolation, I think docker is what you want.
Vagrant is a virtual machine manager, it allows you to script the virtual
machine configuration as well as the provisioning. However, it is still a
virtual machine depending on Virtual Box (or others) with a huge overhead.
It requires you to have a hard drive file that can be huge, it takes a lot
of ram, and performance can be not very good.
Docker on the other hand uses kernel cgroup and namespacing via lxc. It
means that you are using the same kernel as the host and the same file
system. You can use Dockerfile with the docker build command in order to
handle the provisioning and configuration of your container. You have
example at docs.docker.io on how to make your Dockerfile, it is very
intuitive.
The only reason you could want to use vagrant is if you need to do BSD,
Windows or other non-linux development on your ubuntu box. Otherwise, go for
Docker.
-------------------------------------
1
"Mac, Windows and some Linux distributions cannot natively run Docker at
this time so we help you setup a Ubuntu virtual machine and run Docker
inside of that". So unless you're on a mainstream Linux distro, your app
will run inside docker which itself will run inside a VM. – aleemb Jan 28
at 18:52
3
This is true for Mac and Windows, but since docker 0.7, any linux distro
works fine. If you know of a non-working one, please let me know. Also,
unless you have a Mac or Windows stack (which is unlikely but can happen),
you do not want to run Docker anywhere but on linux. The docker client works
fine on Mac, should work soon on BSD and the daemon will eventually support
BSD, Solaris and Mac. – creack Jan 28 at 20:25
=====================================
Disclaimer: I wrote Vagrant! But because I wrote Vagrant, I spend most of my
time living in the DevOps world includes software like Docker. I work with
a lot of companies using Vagrant and many use Docker, and I see how the two
interplay.
Before I talk too much, a direct answer: in your specific scenario (yourself
working alone, working on Linux, using Docker in production), you can stick
with Docker alone and simplify things. In many other scenarios (I discuss
further), it isn't so easy.
It isn't correct to directly compare Vagrant to Docker. In some scenarios,
they do overlap, and in the vast majority, they don't. Actually, the more
apt comparison would be Vagrant versus something like Boot2Docker (minimal
OS that can run Docker). Vagrant is a level above Docker in terms of
abstractions, so it isn't a fair comparison in most cases.
Vagrant launches things to run apps/services for the purpose of development.
This can be on VirtualBox, VMware. It can be remote like AWS, OpenStack.
Within those, if you use containers, Vagrant doesn't care, and embraces that
for example. With Vagrant 1.6, Vagrant has docker-based development
environments, and supports using Docker with the same workflow as Vagrant
across Linux, Mac, and Windows. Vagrant doesn't try to replace Docker here,
it embraces Docker practices.
Docker specifically runs Docker containers. If you're comparing directly to
Vagrant: it is specifically a more specific (can only run Docker containers)
, less flexible (requires Linux or Linux host somewhere) solution. Of course
if you're talking about production or CI, there is no comparison to Vagrant
! Vagrant doesn't live in these environments, and so Docker should be used.
If your organization runs only Docker containers for all their projects and
only has developers running on Linux, then okay, Docker could definitely
work for you!
Otherwise, I don't see a benefit to attempting to use Docker alone, since
you lose a lot of what Vagrant has to offer, which have real business/
productivity benefits:
Vagrant can launch VirtualBox, VMware, AWS, OpenStack, etc. machines. It
doesn't matter what you need, Vagrant can launch it. If you are using Docker
, Vagrant can install Docker on any of these so you can use them for that
purpose.
Vagrant is a single workflow for all your projects. Or to put another way,
it is just one thing people have to learn to run a project whether it is in
a Docker container or not. If, for example, in the future, a competitor
arises to compete directly with Docker, Vagrant will be able to run that too.
Vagrant works on Windows (back to XP), Mac (back to 10.5), and Linux (back
to kernel 2.6). In all three cases, the workflow is the same. If you use
Docker, Vagrant can launch a machine (VM or remote) that can run Docker on
all three of these systems.
Vagrant knows how to configure some advanced or non-trivial things like
networking and syncing folders. For example: Vagrant knows how to attach a
static IP to a machine or forward ports, and the configuration is the same
no matter what system you use (VirtualBox, VMware, etc.) For synced folders,
Vagrant provides multiple mechanisms to get your local files over to the
remote machine (VirtualBox shared folders, NFS, rsync, Samba [plugin], etc.)
. If you're using Docker, even Docker with a VM without Vagrant, you would
have to manually do this or they would have to reinvent Vagrant in this case.
Vagrant 1.6 has first-class support for docker-based development
environments. This will not launch a virtual machine on Linux, and will
automatically launch a virtual machine on Mac and Windows. The end result is
that working with Docker is uniform across all platforms, while Vagrant
still handles the tedious details of things such as networking, synced
folders, etc.
To address specific counter arguments that I've heard in favor of using
Docker instead of Vagrant:
"It is less moving parts" - Yes, it can be, if you use Docker exclusively
for every project. Even then, it is sacrificing flexibility for Docker lock-
in. If you ever decide to not use Docker for any project, past, present, or
future, then you'll have more moving parts. If you had used Vagrant, you
have that one moving part that supports the rest.
"It is faster!" - Once you have the host that can run Linux containers,
Docker is definitely faster at running a container than any virtual machine
would be to launch. But launching a virtual machine (or remote machine) is a
one-time cost. Over the course of the day, most Vagrant users never
actually destroy their VM. It is a strange optimization for development
environments. In production, where Docker really shines, I understand the
need to quickly spin up/down containers.
I hope now its clear to see that it is very difficult, and I believe not
correct, to compare Docker to Vagrant. For dev environments, Vagrant is more
abstract, more general. Docker (and the various ways you can make it behave
like Vagrant) is a specific use case of Vagrant, ignoring everything else
Vagrant has to offer.
In conclusion: in highly specific use cases, Docker is certainly a possible
replacement for Vagrant. In most use cases, it is not. Vagrant doesn't
hinder your usage of Docker; it actually does what it can to make that
experience smoother. If you find this isn't true, I'm happy to take
suggestions to improve things, since a goal of Vagrant is to work equally
well with any system.
Hope this clears things up!