Vagrant is a tool geared towards administering a consistent development environment workflow spanning various operating systems. Docker is a container management tool that can consistently run software provided that a containerization system is present.
There are benefits and drawbacks for each type of virtualized system. If one desires total isolation with guaranteed resources, a full VM would be the strategy to use. For those who only desire to isolate processes from each other and wish to operate a lot of them using a moderately sized host, then Docker/LXC/runC is definitely the strategy to use.
- Vagrant is easier to understand and is easier to get up and running but can be very resource intensive (in terms of RAM and space).
- Docker architecture is harder to understand and can be harder to get up and running but is much faster, uses much less CPU and RAM and potentially uses much less space than Vagrant VM’s.
How does Docker work?
Docker makes use of containers that include your application as well as its dependencies, nevertheless it shares the kernel (operating system) with other containers. Containers run as isolated processes on the host operating system although they are not associated with any specific infrastructure (they are able to run on any computer). Containers are typically more lightweight than virtual machines, so starting and stopping containers is exceedingly fast. Usually development machines don’t have a containerization system built-in, and Docker makes use of a virtual machine with Linux installed to make it work.
Docker is a Linux-only virtual environment (VE) tool, as opposed to a VM tool. It builds on LxC (LinuX Containers), which utilizes the cgroups functionality to allow creation and running of multiple isolated Linux virtual environments (VE) on an individual control host. In contrast to a VM, a VE like Docker doesn’t create its own virtual computer with a distinct OS and processors and hardware emulation. A VE is VM-lite; it rides on the currently present kernel’s image of the underlying hardware, and merely creates a container in order to run one’s apps, and also recreate the OS if desired considering that the OS happens to be merely another application running on the kernel. It places just a little additional load on the system, so in contrast to the traditional VM there is very little overhead when using Docker. Due to the shared kernel, Docker’s isolation isn’t as good as a full VM’s, however it suits many scenarios just fine.
How does Vagrant work?
Vagrant uses virtual machines to run environments independent of the host machine. This is accomplished using what is referred to as virtualization using software like VirtualBox or VMware. Each environment possesses its own virtual machine and is configured by make use of a Vagrantfile. The Vagrantfile tells Vagrant how to set up the virtual machine along with what scripts ought to be run in order to provision the environment. The downside to this approach is that each virtual machine includes not only one’s application and all of its libraries but the entire guest operating system to boot, which can significantly add to the size of the image.
Vagrant lets one script and package the VM config along with the provisioning setup. It is engineered to run on top of nearly every VM tool however, default support is only included for VirtualBox (others are supported through plugins). Vagrant also does integrate with Configuration Management tools for instance Puppet and Chef to provision VM setups and configs.
Where will Docker and Vagrant Shine?
If one needs higher level of separation of hardware resources, then they should use Virtualization (i.e. VMs). Ideal use case can be public cloud solutions where they demand stringent resource separation between VMs running on the same hardware. The implications are that we are guaranteed resources at the hardware level, however at the cost of heavier image and longer startup times. We also get support for more OS platforms like Linux/Unix/Windows etc.
If one does not need strict resource separation and want their application to get bundled with its user-space dependencies then containers are ideal for that. The implications are faster startup times with very lightweight images with lesser isolation and no guaranteed resources at the hardware level. Also, the support for OS platforms is Linux only.
Although Vagrant and Docker appear to be competitors with overlapping feature set, they can be used together in a fashion that their functionality complement one another. In such a scenario, Vagrant can be used to create a base VM, then when one desires to create different configs that all make use of this base VM, use Docker to provision and create different lightweight versions. In other words we can say that Vagrant abstracts the machine whereas Docker abstracts the application.