Packer Machine image builder
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
packer init .packer fmt .packer validate .
packer build .packer build -var-file=<file> .
packer build -only=<name> .
packer inspect .
PACKER_LOG=1 packer build .
Concepts
- Template *.pkr.hcl
- Plugins builders, provisioners
- Temp machine source + provisioners
- Image AMI, box, template
Init & plugins
packer init <dir>
packer init -upgrade <dir>
packer plugins installed
packer plugins required <dir>
packer plugins install <source> [version]
packer plugins remove <source> [version]
packer init -force <dir>
Check & format
packer validate <dir>
packer validate -syntax-only <dir>
packer validate -evaluate-datasources <dir>
packer fmt <dir>
packer fmt -check <dir>
packer fmt -diff <dir>
packer fmt -recursive <dir>
packer inspect <dir>
Build
packer build <dir>
packer build <file.pkr.hcl>
packer build -only=<a>,<b> <dir>
packer build -except=<a>,<b> <dir>
packer build -force <dir>
packer build -parallel-builds=<n> <dir>
packer build -timestamp-ui <dir>
packer build -color=false <dir>
packer build -machine-readable <dir>
Variables
packer build -var <key>=<value>
<dir>
packer build -var-file=<file> <dir>
PKR_VAR_<name>=<value>
*.auto.pkrvars.hcl
packer validate -var-file=<file> <dir>
-no-warn-undeclared-var
Debug & errors
packer build -on-error=ask <dir>
packer build -on-error=abort <dir>
packer build -on-error=cleanup <dir>
packer build -on-error=run-cleanup-provisioner
<dir>
packer build -debug <dir>
PACKER_LOG=1PACKER_LOG_PATH=<file>
packer console <dir>
TMPDIR=<short path>
Template skeleton
packer { required_plugins { docker = { version = ">= 1.0.0" source = "github.com/hashicorp/docker" } }}variable "tag" { type = string default = "latest"}
source "docker" "app" { image = "ubuntu:24.04" commit = true}build { sources = ["source.docker.app"] provisioner "shell" { inline = ["apt-get update"] }}
packer hcl2_upgrade <file.json>
packer fix <file.json>
Recipes
packer init .packer fmt -check -recursive .packer validate -var-file=prod.pkrvars.hcl .packer build -var-file=prod.pkrvars.hcl .
# keeps the machine so you can SSH in and retryPACKER_LOG=1 PACKER_LOG_PATH=packer.log \ packer build -on-error=ask .
packer build -only='app.docker.app' -force .
echo 'upper("web")' | packer console .



