Vagrant vs. Docker: Which Is Better for Software Development Environments?

DZone 's Guide to

Vagrant vs. Docker: Which Is Better for Software Development Environments?

Though Docker and Vagrant do similar things, they're very different. Understand the differences so you can choose the right one for your development environment.

· DevOps Zone ·
Free Resource

Docker took the software development industry by storm, greatly changing the way we develop the software. However, Vagrant is still a viable option. What are the pros and cons of each tool?

"Works on my computer" is the byword of software development describing the situation when the application behaves unexpectedly, as the real production environment conditions differ from the development and staging ones. Such a situation is actually quite widespread, due to the vast variety of hardware configurations, OS'es, software versions and other variables across the application sphere of usage. This sometimes leads to the uncovering of unexpected bugs by end users and, worst of all, the developers have to pay much effort to reproduce and fix them.

The solution to this issue is known and has been around for a while: the developers must the software development environments identical to the production ones, so the app code behaves exactly the same way in development, during testing, staging and in production. There are two main DevOps tools that enable such a functionality: Docker and Vagrant. While acting similarly, these tools differ quite a lot. They have different

  • Scopes of app isolation,
  • Security levels,
  • Speed of launch,
  • Resource consumption, and
  • Operational limitations.

Below, we will compare Vagrant vs. Docker to highlight which of them is better for enabling the software development environments.

Vagrant vs. Docker: Scopes of Isolation

Vagrant from Hashicorp is a solution that enables quick configuration and provisioning of virtual machines (VMs) that help to isolate the application in its own development environment. These VM's work on top of real hardware servers but emulate the virtual infrastructure the developer needs - from OS all the way down to libraries and binaries of the required software - and ensure the app works the same no matter the underlying hardware and software, as long as it runs in the VM.

Docker is an open-source platform that allows isolating the apps within code containers similar to Linux Containers (LXC), though Docker moved from LXC to containerd to enable industry-wide standardization. Instead of creating a virtual computer atop a real hardware, a Docker container is a code package with everything needed to run the app code inside. While a single container is created to run a single app, one Vagrant VM can run multiple interacting apps at once. For Docker containers, this is possible using Kubernetes and dockercompose.

Thus said, containers usually weigh several dozens of MBs and multiple containers with separate apps can run atop a single virtual machine.

Vagrant vs. Docker: Security Levels

As Docker containers use the kernel of the system they run on (be it Linux, Windows or MacOS kernel) there is a possibility that malicious code run within the container will affect other containers on this machine as well as the host operating system. This risk can be mitigated by adding built-in security checks to the container.

With Vagrant the developers must ensure the security of the virtual machine themselves, by installing and configuring any firewalls deemed necessary.

Vagrant vs. Docker: Speed of Launch

As Docker containers are run in separate code packages, they can be launched in under a minute without affecting the work of other system components. On the other side, a Vagrant VM must be totally rebooted to launch the app anew and all the running apps must be restarted afterward

Vagrant vs. Docker: Resource Consumption

Vagrant VM's have to be launched upon the existing host OS's, so they cost a certain amount of resources to sustain themselves. Docker negates the need for the hypervisor and the whole virtualization level, as containers can be run directly atop 3 most popular OS's - Linux, Windows, and Mac OS. This allows a tremendous increase in the resource consumption efficiency - a host running containers boasts 300% increased efficiency as compared to running VM's.

Vagrant vs. Docker: Operational Limitations

While Docker can be launched on any of the most popular software development OS's, it does not have native MacOs support as of April 2018 and requires the developers to launch a VM on MacOS. Thus said, Vagrant can run atop any host OS without limitations, yet after exiting the development and testing environments, the app must run atop host machines in staging and production, where multiple inconsistencies might arise.

Final Thoughts on Vagrant vs. Docker and Which Is Better for Software Development

Docker is a production-ready environment that provides consistent app usage experience throughout the whole software delivery pipeline. Built along industry standards, Docker containerization becomes a vital tool for ensuring software delivery continuity, especially when coupled with Kubernetes, Jenkins and other DevOps tools for CI/CD.

On the other hand, Vagrant is specifically designed for software development purposes, so running it in production is not recommended for the sake of all the reasons described above - excessive resource consumption, slow launch/reboot speed, security configuration complexity.

devops, docker, software development, vagrant

Published at DZone with permission of Vladimir Fedak , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}