Docker vs Vagrant?

Why this two technologies aren’t competing


After reading some blogs with posts about “Docker vs Vagrant” ( like this one and this one) I decided to write about this two technologies and how they are not competing against each other but they are complementing each other.

I’m going to make a little summary about each technology as is established in their respective web pages with a brief explanation. After that, a little explanation in how you can use both technologies to improve your productivity.

Vagrant

Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.
To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.

In simple words, Vagrant is a technology which takes a file ( Vagrantfile ) to install an operating system ( could be anyone, normally is the OS that you will use in your servers or cloud instances ) and install all the libraries and software you need to run the programs and processes that form part of your final application. In other words, Vagrant could install your OS and then your Docker packages to run your Docker containers in your computer and in your server.

All this allows you to create similar environments ( no exactly the same but really close to each other ) where you can test your applications.

So, in summary:

Vagrant is a technology that will allow you to install all you need to develop your application in an easy and simple way.

Docker

Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more.

Again in simple words, Docker is a technology that allows you to run applications inside containers ( that resemble virtual machines but are really different ) which assure you that all the libraries and packages needed by an specific application are always available and are always the same without mattering where you run them. That means that you can make a container for Memcache and another for Redis and you can be sure that in any Linux OS where you run your containers ( including the operating system that Vagrant just installed in your computer or server ), they will have the same behavior.

So, in summary:

Docker is a technology that allows you to run self-contained applications eliminating worries about dependencies and libraries.

How to use both to improve your productivity

If at this point you are still not convinced that you can use both at the same time for your benefit let me give you an example:

  1. Install a Vagrant virtual machine in your computer containing the same OS you will have in your server ( normally Ubuntu Linux 12.04 LTS 64 bits). This means that you can program in any OS you want and still expect your program will run in your server.
  2. Install your Docker packages to create Docker containers inside your virtual machine created for Vagrant. This step is better if you can install them through an script.
  3. Inside your containers put your applications ( Nginx, Memcached, MongoDB, etc)
  4. Configure a shell script, Puppet or Chef script to install Docker and run your Docker containers each time Vagrant begins.
  5. Test your containers in your Vagrant VM inside your computer.
  6. Thanks to providers now you can take the same file ( your Vagrant file ) and just type vagrant up —provider=“provider” where the provider is your next host and Vagrant will take care of everything. For example, if you choose AWS then Vagrant will: Connect to your AMI in AWS, install the same OS you used in your computer, install Docker, launch your Docker containers and give you a ssh session.
  7. Test your containers in AWS and look that they behave exactly as you expect.

As you can see Vagrant and Docker are not competing, they are complementing each other. So, if you are wondering which one you should learn my advice is to learn both, you could benefit a lot from both technologies.


P.S If you found any grammar mistake please let me know to fix it. Thanks!

Show your support

Clapping shows how much you appreciated Marcos Otero’s story.