Virtualization technology has always been a very important thing in the computer world.
The first thing most programmers think of when they hear this word is VMware running Linux under Windows.
And this “VMware running Linux” is what we call a Virtual Machine.

The main benefit of a virtual machine is that you can create a development environment different from the host OS
(for example, most offices use Windows computers)

But this convenience for development also leads to it being kind of a hassle to initialize this kind of environment
And when a project gets to a certain stage and depends on certain changes in the environment itself
creating a virtual machine dev environment from scratch becomes very tedious
Vagrant is a tool meant to solve this kind of tedium

Vagrant

According to the official statement

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

Vagrant itself doesn’t do the virtual machine work, but allows users to use VMware|VirtualBox|AWS to launch VM images. They call these Providers.
Of course, images in Vagrant are called Boxes, and many companies have already prepared initialized Boxes here that you can use directly
Vagrant also provides initialization scripts (Provisioning) for Boxes — these init scripts can use more scripting tools to complete the configuration of the Box.

So compared to traditional virtual machines, Vagrant stands on the shoulders of giants and accomplishes automation.

Docker

The Docker project’s goal is to achieve a lightweight virtualization solution. The biggest difference between it and Virtual Machine is that Docker containers share the OS kernel
vm
docker

So the comparison between Docker and traditional virtual machines is obvious:

FeatureDockerVirtual Machine
StartupSecondsMinutes
SizeUsually MBUsually GB
PerformanceNear nativeWeaker than native
Single host countThousandsUsually dozens
KernelSharedIndependent

Vagrant vs Docker

Honestly, these two shouldn’t be put together for comparison — their virtualization levels aren’t on the same scale.
And these two aren’t contradictory: if you need to run several specific Linux distributions on a Windows system, you can totally use Vagrant + Virtual Machine first and then embed several Dockers inside.

If you must compare them, if you need to run cross-platform virtualization, use Vagrant; otherwise, use Docker

Lastly let me throw in a comparison table:

FeatureVirtual MachineVagrantDocker
VirtualizationFull virtualizationNoneSystem virtualization
Image mgmtNoneYes, usually GBYes, usually MB
PerformanceWeaker than nativeWeaker than nativeNear native
KernelIndependentIndependentShared

References

  1. 《Docker — From Beginner to Practice》
  2. Why Vagrant
  3. Docker is Not a Virtual Machine
  4. Should I use vagrant or docker