packer
HashiCorp's tool for creating machine images across multiple platforms
TLDR
Build image from template
SYNOPSIS
packer command [-var key=value] [-only target] [-except target] [options] template
DESCRIPTION
Packer is HashiCorp's tool for creating machine images across multiple platforms from a single source configuration. It automates image building for AWS, Azure, GCP, Docker, VMware, and many other platforms.
Templates define builders (where to create images), provisioners (how to configure them), and post-processors (what to do with finished images). Modern templates use HCL format (.pkr.hcl), though JSON is still supported.
Builders create the initial machine instance. Examples include amazon-ebs for AWS AMIs, azure-arm for Azure images, and docker for containers. Each builder handles platform-specific details.
Provisioners run after the machine boots: shell scripts, Ansible, Chef, Puppet, or file uploads configure the image. Multiple provisioners run in sequence, building up the configuration.
Post-processors handle finished images: upload to registries, compress, or create Vagrant boxes. Images can be distributed to multiple regions or clouds.
PARAMETERS
build
Build image from template.validate
Check template syntax.init
Install required plugins.fmt
Format template files.inspect
Show template components.console
Interactive HCL console.-var key=value
Set variable value.-var-file file
Variable definitions file.-only name
Build only specified builders.-except name
Skip specified builders.-force
Force build, overwriting existing.-on-error ACTION
Action on error: cleanup, abort, ask, run-cleanup-provisioner.-debug
Debug mode with breakpoints.-parallel-builds N
Parallel build limit.-timestamp-ui
Add timestamps to UI output.
CAVEATS
Platform credentials required for cloud builders. Build times vary significantly by platform. Large images require more time and storage. Debug mode pauses between steps. JSON templates are deprecated but still work. Plugin initialization required for non-bundled builders.
HISTORY
Packer was released by HashiCorp in 2013, created by Mitchell Hashimoto. It addressed the challenge of creating identical machine images across multiple platforms. The tool became essential in DevOps workflows for immutable infrastructure. In 2020, HCL2 template format was introduced, aligning with Terraform syntax.
