Vagrant is a great tool from HashiCorp, ensuring the continuity and efficiency of the software development process. It allows rapid deployment and configuration of development environments from ready Vagrant Boxes, ensuring any developer can replicate the production environment on their machine. It also has a Docker provider feature, granting it even more operational flexibility. What is Vagrant Docker provider and how to use it best?
Vagrant operates Virtual Machines (VMs), which work on any OS atop a hypervisor layer. Within the limits of the VM, Vagrant can help emulate any production environment conditions — any OS, any set of drivers, libraries, binaries, and software of any versions. Therefore, it is great for bug fixing, when the conditions of the production environment differ a lot from the configuration of the development environment — which is almost always the case.
Vagrant can work with various providers, serving as building blocks for the virtual infrastructure. VirtualBox is the default choice, but Docker provider was also added to Vagrant some time ago. Therefore, Vagrant VM can be used as a base host for Docker containers, thus enabling a smooth transition from server-based legacy infrastructure to a modern, cloud-based infrastructure operating Docker containers on Kubernetes clusters.
What are both Docker and Vagrant good for? Read here:
They are great for isolating apps and processes for the purposes of development, bug fixing, feature development or splitting the monolithic app to microservices. However, there are several differences in their modus operandi:
- Vagrant isolates a virtual machine. It needs an underlying OS and hypervisor. While guest OSes are separate for each VM, they all depend on the host OS to function.
Docker isolates an app runtime. Each container holds everything needed to run it and operates independently of the processes in other containers.
- Vagrant security depends on host security. For the same reason as with isolation scope, Vagrant uses only the security measures provided by the underlying infrastructure, because adding antivirus and firewall to each VM would seriously undermine their performance level.
Docker containers are secure by design. Their main benefit is the ability to delete and redeploy any singular container at once so that gaining the malicious access to a containerized app is utterly useless for the hacker.
- Vagrant speed of launch depends on the resources available to the underlying host. Depending on the complexity of the app and the server resources available, Vagrant VM might launch or reboot in several seconds or in a couple of minutes.
Docker containers launch in milliseconds, as they are lightweight packages of code enveloping the app with all the needed runtime. They are composed out ofDocker images with a single command and can be deleted and redeployed just as swiftly.
- As for the resource consumption, Vagrant VMs have to dedicate a certain amount of server resources to running a host OS and a hypervisor layer.
Docker containers can be launched even on bare metal server clusters and need no virtualization aside from an installed Docker platform. Thus said, several (or even several dozens) of Docker containers can run atop a single Vagrant VM.
Conclusions on what is Vagrant and Docker
Thus said, Vagrant VMs are a great choice for delivering software development environments, while Docker containers are a secure and efficient way to run the apps in production. We hope you now know what is Vagrant and Docker and where to use each of them best!