Vagrant vs Docker

Independent Environmental Virtual Machines


15 Apr 2017 View Comments
#vagrant #docker #virtualization #virtual #machines #computer

Last Friday, I was at my previous company to hang out with my ex-colleagues and we had a brief chat on docker vs vagrant, but enough to catch my attention and I ended up writing a blog post about it this week. Both of them have very interesting usage yet have quite different colors.

Let’s assume that we are going to deploy a project in a server. We will first need a server, then need to set necessary server settings, not to mention project settings. The list goes on and on to have a successful deploy. The project may use certain web server like a tomcat/apache/Nginx, which may use specific database requiring us to install libraries to use those databases. We finally need to bring the source code which would execute in this environment which may require us to install hundreds of dependencies associated to it. When this is all done, we “may be” able to run this project. Well, chances are that you will miss a step in doing all of the steps above and problems occur. Let’s call everything discussed here as “deployment” step. Just like git controlling the source codes, we can control this “deployment” in a tool like a Docker or Vagrant.

Vagrant

Let’s start with Vagrant. Vagrant is a simplified VM manager. For example, let’s assume that you would like to install Ubuntu with your project settings on your Mac. Unless you install Ubuntu freshly on your Mac, you have to first install virtual machine regardless, then you will need to install the Ubuntu image then proper settings for your project. In order to simplify all these steps to get to that state, Vagrant had been introduced. Vagrant works as a box, let’s take a quick look at how it works.

  1. Box: OS image + settings (CPU, Memory, etc)
  2. Vagrant File: Create the file by running, “vagrant init”. It describes the kind of the box.
  3. Vagrant up: This will install and create the VM.
  4. Vagrant ssh: connect using ssh into the VM.

Docker

Most of the VMs we know all have the Host OS and there is a hypervisor on top of it. Then there we add Guest OS on top of this VM. However, docker would simplify all this. Docker would not require any Hypervisor or Guest OS, it serves multiple containers which contain the differences from the host OS. For example, if host OS was a Ubuntu and you have CentOS as a container, then docker sees the differences in between the two and packages separately. This is called Guest OS Isolation. So you eventually have a light weight VM instead of full blown VM. Docker serves more than this. You can develop, test, staging, release server environment into one and manage them efficiently. If you look at docker community closely, they have well maintained docker hub where people would share all sorts of images out there to make it a container. You can also control versions of the image like Git where you can push/pull just like code versioning.

VM vs Docker
VM vs Docker

Differences

Vagrant is a VM manager so it’s purpose is quite different from the Docker. Vagrant is used to creating a VM so it essentially works similar to traditional VM but in a slightly better way. Docker’s purpose is actually quite different. Docker provisions and creates different lightweight versions of VM (called containers).

Quick Summary of differences:

Docker Vagrant
Container Type Hypervisor Type
Host OS is same Host OS serve different OS
Could Take Time Immediate
Linux Only Linux, Unix, Windows

See below image for comparing between Vagrant and Docker:

Vagrant and Docker
Vagrant and Docker
Share this post

Me

I am a passionate software developer working in Downtown, Vancouver. I strongly believe in art of algorithms and together with it to write clean and efficient software to build awesome products. If you would like to connect with me, choose one from below options :) You can also send me an email at