Docker Vs. Vagrant

Docker Vs. Vagrant

“If you want to manage machines, you should use Vagrant… If you want to build and run application environments, you should use Docker.”

– Solomon Hykes, the author of Docker

In other words, Vagrant manages virtual machines and Docker packages apps into containers. But even with his explanation, it can be quite difficult to wrap our heads around what it all means

Imagine you have two pieces of real estate. The first is called Vagrantland and the second is called Dockertown. They’re both the same size and have the same underlying infrastructure

Your job as a developer is to add stores, restaurants, and other businesses to it because right now, it’s just an area of land with nothing on it.

In Vagrantland, every time a business is added, a new building must be constructed. For example, to add a coffee shop you need to construct the physical shop and set up the building infrastructure (e.g., electricity, lighting, water). Once the building is erected, you add the necessary ingredients to make the place look and feel like an actual coffee shop.

Afterward, you decide to add a furniture store, you need to build a physical store with the same infrastructure. Then, the interior design and products will be added to make the store look like it’s selling furniture.

So you could probably tell that adding a business can be quite cumbersome and hard to scale in Vagrantland.

Let’s switch to Dockertown. First, a single building is constructed with all the infrastructure set up, just like a building in Vagrantland. The difference, however, is that the building in Dockertown acts like a mall. So whenever a new business is added, it simply takes up space inside the building. For instance, when a jewelry shop called “Ruby and Reals” is added, it simply finds a place in the mall and sets up the shop with the materials it needs to sell gems. And when a fruit stand called “Mongo” is added, it takes up a small space in the mall and starts doing business right away.

What’s efficient here is that both businesses share the same building infrastructure such as the lighting system and the bathroom facilities. In this scenario, adding, removing, and changing businesses is fast, easy, and scalable.

So let’s bring everything together. What’s similar between Vagrant’s virtual machines and Docker’s containers is that they both sit on top a host operating system. The difference, on the other hand, is how the application is run. For Vagrant, each virtual machine includes a guest operating system with the application and its libraries and binaries. For Docker, the containers don’t need a guest OS for each application since they all share the same kernel.

Let’s know how each of them work:

Vagrant

Vagrant is a virtual machine manager. It is an open- source software product which is designed to build and configure virtual environments for DevOps process. It runs on top of almost any virtual machine like VirtualBox, VMWare etc. With Vagrant, you can create as many virtual operating systems you need and run them all on a shared hardware.

Docker

Unlike Vagrant, Docker created virtual containers. It virtualizes the operating system allowing you to create as many software as you want and run them all on the shared operating system.

Issues Related to Docker and Vagrant

Each of these has some challenges while dealing with. Let us take a look at some of them:

  • Virtualization Limitation
    Docker only supports the running containers that virtualize a Linux environment. You cannot test it on windows or BSD environment in production.
  • Resource Isolation
    Docker containers use the same kernel of the host-machine and are not fully separated. This weak resource isolation is not accepted in case of some of the applications.
  • Overhead Costs
    The overhead costs associated with Vagrant are very large. It requires a lot of memory to run that in most cases the user has to rely on virtual memory. It simply cannot be run on computers with less than 4 GB of RAM and very hard to run on the computers with 8 GB of RAM.
  • Startup Time
    The Vagrant box generally takes a lot of time to startup. This time varies with how powerful the computer is. You have to wait for almost 5 minutes with powerful computers and more than 7 minutes (on an average) with normal computers. This much waiting time can be a bit annoying.

Benefits of Docker and Vagrant

Docker and Vagrant have their own benefits for the users. Let take a look at some of them:

Docker

  • Memory Usage
    Docker uses only that much RAM and CPU resources as needed. Computers with less RAM can also easily run Docker. It does not involve the entire overhead of running a full virtual machine.
  • Startup Time
    The startup time of docker is quite less as it does not involve setting up of the entire virtual machine. It generally takes a few seconds to set up Docker.
  • Windows Compatibility
    Docker does not only work well with Linux but works well with Windows as well. It is a major advantage of using Docker for building applications.

Vagrant

  • Flexibility
    Unlike Docker, Vagrant supports many operating systems and this flexibility feature gives brownie points to the Vagrant.
  • Usability
    Vagrant architecture is easy to understand, use and run on different operating systems.
  • Simulated Deployment
    Vagrant enables the users to use VirtualBox, Hyper-V, VMware and AWS setup and configure the virtual machine. This allows the quick testing of the deployment scripts and routines.

Conclusion

docker-vs-vagrant-conclusion

Docker is gaining astonishing popularity among the developers at the present. It being more flexible, scalable and faster (which is 10x faster) than the virtual machine is the reason behind its increasing popularity. Using Docker, you can save a lot of time while preparing portable and the reproducible environment almost anywhere. Docker is a good and lightweight alternative to Vagrant.