Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Troubleshooting and Alternatives

Vagrant vs Docker and Alternatives

Compare Vagrant with Docker, Docker Compose, dev containers, Multipass, WSL, Packer and cloud dev environments, and decide when each tool is the right choice.

Vagrant is one of several ways to get a reproducible development environment. Containers, lightweight VM managers and cloud workspaces overlap with it, and each wins in some situations. This lesson compares them honestly, so you can choose the tool that fits the job instead of the one you already know.

What problem are we solving?

Every option below answers the same question: "How does everyone on the team get the same working environment with one command?" They differ in how much of an operating system they include, how fast they start, and how closely they match production.

Two ways to isolate

Virtual machine Own kernel, full OS
Container Shared kernel, one process

Vagrant manages VMs; Docker manages containers.

1 / 2

Vagrant versus Docker

Vagrant (with a VM provider) Docker
Unit A full virtual machine A container (one process tree)
Kernel Its own Shared with the host (or Docker's Linux VM)
Startup Tens of seconds to minutes Usually under a few seconds
Memory and disk Hundreds of MB to GB per machine Tens of MB per container
Init system and services Full systemd, multiple services, cron, SSH Usually one service per container
Match to a production VM Very close Close to a production container
Tooling for teams Vagrantfile, boxes Dockerfile, Compose, registries
Best for Practicing server setup, testing config management, software that expects a whole machine Packaging apps, microservices, CI, production parity with containers

Neither is better in general. Use Vagrant when the thing you are building is a server: an Ansible playbook, a Linux service, a kernel setting, a firewall, an install script. Use Docker when the thing you are building is an application that you will run as a container in production.

They also combine well. Run the Docker provider (see the Docker provider), or use Vagrant to create a Linux VM that hosts Docker on a machine without a native Docker engine.

Docker Compose and dev containers

Docker Compose describes several containers in one compose.yaml. It is the container-world equivalent of a multi-machine Vagrantfile and is the default choice for stacks of web, database and cache in modern projects.

YAML
services:
  web:
    build: .
    ports: ["8080:8000"]
    depends_on: [db]
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: dev

Dev containers (the devcontainer.json format supported by VS Code and other editors) put your editor inside a container, with the language tools and extensions installed. They solve "everyone has the same compiler and linters" well, but they are not a substitute for a full machine when you need an init system.

Other tools in the same space

Multipass

Canonical's Multipass launches Ubuntu VMs from a single command (multipass launch --name dev), uses the platform's native hypervisor (Hyper-V, QEMU, HyperKit) and supports cloud-init. It is simpler than Vagrant for "give me an Ubuntu box", but offers less configuration as code.

WSL 2

On Windows, the Windows Subsystem for Linux gives you a real Linux kernel with fast file access inside its own file system. For application development it often replaces Vagrant entirely. It is not a disposable, per-project machine unless you create and export distributions deliberately.

Lima and Colima

On macOS and Linux, Lima runs Linux VMs with an easy YAML config; Colima builds on it to provide a container runtime. They are good native choices on Apple silicon.

Packer

Packer builds machine images from a template. It does not run your daily environment; it produces boxes (and cloud images). Many teams use Packer to build the base box and Vagrant to consume it, as discussed in packaging and private boxes.

Cloud and remote environments

GitHub Codespaces, Gitpod and similar services run your environment on a server and give you an editor in the browser or via remote connection. They remove local hardware limits and onboarding steps, but cost money, need a network and tie you to a provider.

Configuration management without Vagrant

Ansible, Chef, Puppet and Salt describe how to configure a server. Vagrant can call them as provisioners, so the same playbook configures your local VM and your production server. This is one of Vagrant's strongest use cases.

A decision guide

  1. Are you deploying containers to production? Use Docker and Compose for development as well.
  2. Are you configuring real servers (VMs or bare metal)? Use Vagrant with the same provisioner you use in production.
  3. Do you need only a clean Ubuntu shell? Multipass or WSL 2 is lighter.
  4. Are your developers on Apple silicon? Check box and provider support first; Lima, Docker or Parallels with Vagrant are viable.
  5. Is the setup too heavy for laptops? Consider a remote environment.
  6. Do you teach or study operating systems or networking? Vagrant is excellent: you can break a machine, destroy it and start over in minutes.

A stand-in: scoring the options

Choosing by checklist keeps the debate honest. This Ruby program scores the tools against weighted needs. The weights and scores are opinions, not facts; change them to match your project.

Ruby Weighted tool chooser

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with gets), it gets the next line from this box.

Try raising the weight of "fast start" and watch the ranking change. That is the lesson: the right tool depends on which needs matter to you.

Common mistakes

  • Using Vagrant to run a single web app that Docker would start in a second.
  • Using a container to learn system administration, where there is no init system or full filesystem to practice on.
  • Treating the choice as permanent. Environments can move: a project can start with Vagrant and later gain a Dockerfile.
  • Ignoring production. The best development environment is the one closest to where the code will run.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which is the main reason to choose Vagrant over Docker?

    VMs behave like real servers: systemd, multiple services, firewalls and kernel settings are all available.
  2. 2. What does Packer do?

    Packer produces images; Vagrant (or a cloud) then runs them.
  3. 3. Which tool is the container-world equivalent of a multi-machine Vagrantfile?

    Compose describes several containers, their networks and volumes in one file.
  4. 4. You deploy containers to production. What is the best default for local development?

    Matching production is the strongest argument; containers in dev and prod keep them aligned.

Summary

  • Vagrant gives you full virtual machines; Docker gives you light containers. Choose by what you are building and where it will run.
  • Compose, dev containers, Multipass, WSL 2, Lima, Packer and cloud environments each cover part of the same space.
  • Vagrant shines for server configuration work, testing Ansible/Chef/Puppet code and learning operations.
  • Decide from your needs, not habit, and keep the environment close to production.

Next: Project: a LAMP stack environment