Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 36 ยท Builders and Provisioners

Packer Builders Overview: Cloud, VM and Container Sources

Compare Packer builders for clouds, hypervisors and containers, learn the common settings they share, the Docker and null builders in detail, and how to choose a builder.

A builder (in HCL templates: the type of a source block) is the part of Packer that knows one platform. It creates a temporary machine, gives Packer a way to connect to it, and at the end turns the machine's disk into an artifact. Everything else in your template (provisioners, post-processors) works the same no matter which builder you use. This lesson maps the builder families, explains the settings they share and helps you choose.

Packer cannot run on this site, so builder configurations are read-only. The Python stand-in at the end is a small decision helper, not a Packer feature.

Three families

Builder families

Cloud AWS, Azure, Google, Oracle, DigitalOcean.
Virtualization QEMU, VirtualBox, VMware, Hyper-V, vSphere.
Containers Docker, LXC, Podman-compatible flows.

Each one is a plugin.

1 / 2

Cloud builders launch an instance in your account, provision it, snapshot it and delete it. Examples: amazon-ebs, azure-arm, googlecompute, digitalocean, hcloud, oracle-oci, openstack, linode. They need credentials and cost a few cents per build.

Virtualization builders run on a hypervisor, either on your computer or on a cluster. Some boot from an ISO installer and automate the installation with kickstart, preseed, cloud-init or an autounattend file (qemu, virtualbox-iso, vmware-iso, hyperv-iso, vsphere-iso). Others start from an existing image or template and only provision it (virtualbox-ovf, vmware-vmx, vsphere-clone, proxmox-clone).

Container builders build container images by running a container, provisioning it and committing the result (docker).

Naming tells you the starting point: -iso starts from an installer ISO, -ovf/-vmx/-clone starts from an existing machine, -ebs starts from a cloud image and saves an EBS-backed image.

What every builder needs to answer

No matter which platform, a source has to say:

  1. Where do I create the machine? (region, project, datacenter, host)
  2. From what do I start? (image ID, ISO URL and checksum, base container)
  3. How big is it? (instance type, CPUs, memory, disk size)
  4. How do I connect? (communicator, user name, key, timeout)
  5. What do I save? (image name, tags, format, regions to copy to)
  6. How do I shut down? (a shutdown command, or the platform stops it)
HCL
source "googlecompute" "ubuntu" {
  project_id          = "my-project"
  zone                = "europe-west3-a"
  source_image_family = "ubuntu-2404-lts-amd64"
  machine_type        = "e2-small"
  ssh_username        = "packer"
  image_name          = "web-base-v1"
  image_family        = "web-base"
}

Read the example with the six questions in mind: where (project_id, zone), from what (source_image_family), how big (machine_type), connect (ssh_username), save (image_name, image_family).

Settings shared by many builders

Setting group Examples Meaning
Communicator communicator, ssh_username, ssh_timeout, ssh_private_key_file, winrm_username, winrm_use_ssl How Packer logs in
Boot (ISO builders) boot_command, boot_wait, http_directory Keystrokes that start an unattended install
Shutdown shutdown_command, shutdown_timeout How the VM is powered off cleanly
Output output_directory, format, vm_name Where a local disk image is saved
Tags / labels tags, run_tags, labels Metadata on image and temporary resources

The Docker builder

The Docker builder has three ways to finish. Pick exactly one:

HCL
source "docker" "commit_example" {
  image  = "ubuntu:24.04"
  commit = true                        # keep as a local image
}

source "docker" "export_example" {
  image       = "ubuntu:24.04"
  export_path = "image.tar"            # write a tar file (docker import/load later)
}

source "docker" "discard_example" {
  image   = "ubuntu:24.04"
  discard = true                       # run provisioners, keep nothing (useful for testing scripts)
}

Useful extras:

  • changes = ["ENV APP_ENV=prod", "ENTRYPOINT [\"/app\"]"]: Dockerfile-style instructions applied when committing (CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, USER, VOLUME, WORKDIR, ONBUILD).
  • volumes = { "/host/cache" = "/cache" }: bind mounts while building.
  • privileged = true: run with extended privileges (needed to test systemd, avoid otherwise).
  • run_command: customize how the container is started; the default keeps it alive in the background.
  • pull = false: do not pull the base image if it exists locally.
  • platform = "linux/arm64": build for another architecture.

Packer's Docker builder is not a replacement for docker build with BuildKit caching. It shines when you want the same provisioners (for instance Ansible) to configure a container and a VM.

The null builder

null is a built-in builder that creates no machine. It connects to an existing host (or to none) so you can test provisioners and post-processors:

HCL
source "null" "local" {
  communicator = "none"
}

build {
  sources = ["source.null.local"]
  provisioner "shell-local" {
    inline = ["echo testing a local script"]
  }
}

It is excellent for developing shell-local steps or manifest handling with zero cost.

Choosing a builder

You want... Use
An AMI for EC2 amazon-ebs (most common), amazon-ebssurrogate for custom partitioning
An Azure managed image or Compute Gallery image azure-arm
A Google Compute Engine image googlecompute
A container image sharing provisioners with VMs docker
A local test VM, no cloud virtualbox-iso or qemu
A VMware template in vSphere vsphere-iso or vsphere-clone
A KVM/OpenStack-compatible QCOW2 file qemu with format = "qcow2"
A Proxmox template proxmox-iso or proxmox-clone
To test provisioners without a machine null

Several of these come from vendor or community plugins, not HashiCorp; check the plugin's release notes before depending on it.

A stand-in builder chooser

This Python stand-in encodes the table above as a function of a few answers. It demonstrates how the choice follows from where the image will run and where you build it.

Python Stand-in: choose a builder

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 input()), it gets the next line from this box.

Practical advice

  • Start with the cheapest builder that exercises your provisioners (Docker or QEMU) and move to the cloud builder later.
  • Keep one source per platform and share a single build for the steps.
  • Prefer building from official vendor images (ubuntu, debian, Amazon Linux, Windows Server) and updating them over hand-made ISOs.
  • Name images with a version or timestamp so every build produces a unique, traceable artifact.

The next lessons cover the Amazon EBS builder and the VM builders in detail.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the -iso suffix in virtualbox-iso indicate?

    -iso builders begin from an installation ISO; -ovf, -vmx and -clone builders start from an existing machine.
  2. 2. Which Docker builder setting throws the result away, useful to test provisioning scripts?

    discard = true runs the build and keeps no image.
  3. 3. Which question does machine_type answer for the googlecompute builder?

    machine_type chooses the size of the temporary instance.
  4. 4. What does the null builder do?

    null is built in and connects to nothing (or an existing host), so you can try steps without a real machine.

Summary

  • Builders come in three families: cloud, virtualization and containers; each is a plugin.
  • Every source answers six questions: where, from what, how big, how to connect, what to save, how to shut down.
  • The Docker builder finishes with commit, export_path or discard; null creates no machine at all.
  • Suffixes -iso, -ovf, -vmx, -clone and -ebs tell you the starting point.
  • Start cheap and local, then move to cloud builders once provisioners work.

Next: The Amazon EBS builder