Vagrant vs Docker
Vagrant vs. Docker: which is better for software development environments? Comparison of Docker and Vagrant in production
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 Vagrant and Docker?
“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 uncovering of the 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 the development, during testing, staging and in production. There are two main DevOps tools that enable such functionality: Docker or Vagrant. While acting similarly, these tools differ quite a lot. They have different:
- scopes of app isolation,
- security levels,
- speed of launch
- resource consumption
- operational limitations
Comparing Vagrant vs Docker for development
Both Docker and Vagrant can provide virtualized development environments, but they approach the problem very differently. Below we will compare Vagrant vs. Docker to highlight which of them is better for enabling the software development.
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 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 command.
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
Docker can be launched on any of the most popular software development OS’s. Thus said, Vagrant can run atop any host operating system 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.
However, while comparing Docker with Vagrant seems to show Docker vastly superior, there are lots of scenarios where Vagrant software development environments shine. We describe them below.
Using Vagrant for software development
Vagrant is lightweight virtualization software, which DevOps engineers, developers and UI/UX designers can use to quickly spin up and configure any kind of software development environments. Vagrant works atop any versions of the most popular operating systems — Windows, Linux, MacOS and provides a single virtualization layer to ensure AWS instances, Docker containers, VirtualBox instances, Hyper V, VMWare units are operated smoothly across various servers.
Why would anyone love to work with Vagrant development environment? Because it’s great to continue developing your project while commuting by a train or to be able to showcase your project on a conference on any available machine or collaborate with a remote development team. Vagrant is better than Docker in that regard, as you don’t need to download an image to construct a container — all you need is a Vagrantfile of your development environment, so it can be sprung quite fast.
Vagrant consists of 3 major components:
- Vagrant Box is essentially a virtualized development environment ready for launch
- Vagrant Provider is an underlying system that hosts Vagrant. In most cases, Virtual Box will suffice, but for the sake of microservices development and other goals, it is better to use Vagrant with Docker containers.
- Provisioner — a configuration management system used to manage Vagrant virtualized environments, mostly Chef, Puppet, Salt, Ansible. Lately using Docker vs Kubernetes became much more widespread. However, it cannot be done on the move or on a business trip, as configuring Kubernetes is much more complicated as compared to using virtual machines built by Vagrant.
The most important Vagrant benefits are as follows:
- Cross-platform portability. Using Vagrant allows you to work with your coding tools of choice, on any underlying platform and create portable virtualized software development environments that will work equally well on any operating system, be it Windows, MacOS or Linux. This ensures a distributed software delivery team will work in identical environments with the same dependencies, regardless of the underlying host system configuration.
- Workflow unification. Using Vagrantfiles is similar to working with Kubernetes or Terraform manifests. They are written in a declarative language and ensure the transparency, repeatability and automation of the development configuration process. A DevOps engineer, a developer, a UI/UX designer or a QA engineer have the same workflow with Vagrant. Everything works in a very simple and understandable way.
- Consistency throughout the delivery pipeline. Regardless of the components and modules used by various participants of the software delivery pipeline on various stages of the workflow, Vagrant integrates well with a huge range of platforms, Everybody can use their favorite text editor, IDE or browser — the resulting code will be the same.
Vagrant can also be used for running production environments for small-scale projects. This is hugely beneficial due to the simplicity of spinning up new Vagrant virtualized environments and the fact that the processes and workflows are identical in development and in production.
However, the main difference between Docker and Vagrant in production is the sheer simplicity, security, and scalability of managing Docker virtual environments en masse.
Using Docker in software development and in production environments
Below we list 8 reasons why Docker development environment is a worthy alternative to Vagrant virtualized development environments and why Docker is superior for running production environments.
ROI and savings at scale
When adopting new technology, especially such a ground-breaking one as Docker, the businesses look for ROI and cost savings first and foremost. Docker is able to provide tremendous cuts in expenditure, as it allows running the same apps using fewer resources. This means the company can pay less for the maintenance of their server fleet and employ fewer engineers, who will be able to drive more value with less effort.
Standardization across all IT operations
Standardization is actually the biggest technological benefit of using Docker with development environments, as well as for testing, staging and in production. Docker containers are immutable, meaning that all the containers built from the same image always operate the same regardless of their surrounding. Such standardization allows removing excessive tools and platforms from the software delivery pipeline and building the optimal toolkit and workflow for your company so that every member of the IT team works in the same environment.
Efficiency of CI processes
When the same image is used to build Docker dev environments, testing environments, staging environments, and production environments — you receive the continuity and efficiency of the CI/CD pipelines, as the same tools and frameworks are used throughout all stages of software delivery.
Just as working with Docker containers is easy for development, it is also hugely beneficial for maintainability of all your company IT infrastructure. Not only will you forget about “works well on my machine”, but you will also get rid of many legacy processes and solutions that hamper your company’s ability to scale the IT operations and adapt to the changing business goals.
Simplicity and repeatability of configurations
Just as with Vagrant, Docker configurations are saved in Dockerfiles that can be stored in version control system of your choice and adjusted should the need arise, with the ability to quickly choose the version you need at the moment.
As we explained before, launching a Docker container takes only seconds, as it does not need to boot a guest OS to allow the app to work. You can spin up hundreds of Docker virtual machines in a matter of seconds and delete them with ease, without losing any information or paying any unneeded expenses.
Automated testing and Continuous Deployment
Obviously, working with Docker containers means all testing and updates are easy. The new app code is tested against automated unit tests and if the tests succeed — the changes are made to the base Docker image. Then the containers in production can be rebooted through rolling updates — and a new app version goes live without any downtime and backup/restore issues.
Docker containers run everywhere where Docker is installed. The underlying infrastructure can be built using AWS, GCP, Azure, OpenShift, OpenStack, DigitalOcean or any other cloud computing or virtualization provider. Containers prevent vendor lock-in and allow using a flexible multi-cloud infrastructure, where any components can be replaced if the need arises.
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.
At IT Svit we have ample experience with using both Vagrant and Docker for software development, but we sincerely recommend to stick with Docker for the needs of supporting the app in production. What’s your experience with Docker and Vagrant? Which of them do you find better for software development? Did we miss anything important? Please tell us in the comments below!