Packer — Automated Machine Image Building for Any Platform
Packer is HashiCorp's tool for creating identical machine images across multiple platforms from a single source. Build AMIs, Docker images, GCE images, and VMware templates in one pipeline — the standard for immutable infrastructure.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install 63c1417d-37c8-11f1-9bc6-00163e2b0d79 --target codexÀ exécuter après confirmation du plan en dry-run.
What it is
Packer is HashiCorp's open-source tool for creating identical machine images across multiple platforms from a single source configuration. It supports Amazon AMIs, Docker images, Google Compute Engine images, VMware templates, and many more builders through a plugin system.
Infrastructure engineers, DevOps teams, and platform teams use Packer to enforce consistency between development, staging, and production environments. By baking all dependencies into a machine image, you eliminate configuration drift that occurs when provisioning servers at boot time.
How it saves time or tokens
Without Packer, teams either provision servers at boot time (slow, error-prone) or manually create and snapshot images (inconsistent, undocumented). Packer automates the entire process: launch a temporary instance, run provisioners (shell scripts, Ansible, Chef), capture the image, and destroy the instance. The result is a versioned, reproducible artifact.
A single packer build command replaces a multi-step manual process that typically takes 30-60 minutes of an engineer's time per image variant.
How to use
- Install Packer:
brew install packer
- Write an HCL template and build:
packer init aws.pkr.hcl
packer validate aws.pkr.hcl
packer build aws.pkr.hcl
- The output is a machine image ID (AMI, Docker tag, etc.) ready for deployment.
Example
A Packer HCL template for building an AWS AMI:
packer {
required_plugins {
amazon = {
source = "github.com/hashicorp/amazon"
version = "~> 1.3"
}
}
}
source "amazon-ebs" "ubuntu" {
ami_name = "my-app-{{timestamp}}"
instance_type = "t3.micro"
region = "us-east-1"
source_ami = "ami-0c7217cdde317cfec"
ssh_username = "ubuntu"
}
build {
sources = ["source.amazon-ebs.ubuntu"]
provisioner "shell" {
inline = [
"sudo apt-get update -y",
"sudo apt-get install -y nginx"
]
}
}
This template launches a t3.micro instance, installs nginx, and captures the result as a timestamped AMI.
Related on TokRepo
- DevOps Tools -- Infrastructure automation tools for building and deploying
- Automation Tools -- CI/CD pipelines and build automation workflows
Common pitfalls
- Forgetting
packer initbefore the first build. Packer 1.7+ requires explicit plugin installation via init, and builds fail without it. - Not cleaning up old AMIs. Each build creates a new image; set up a lifecycle policy or script to deregister images older than N days.
- Provisioner ordering matters. Shell provisioners run sequentially; if an early step fails, subsequent steps may succeed silently with a broken base. Use
set -ein shell scripts.
Questions fréquentes
Packer supports AWS (AMI), Google Cloud (GCE), Azure (managed images), Docker, VMware, VirtualBox, Proxmox, and many more through its plugin system. You can build images for multiple platforms simultaneously from the same template.
Packer creates machine images. Terraform provisions infrastructure using those images. A typical workflow is: Packer builds an AMI, then Terraform references that AMI ID to launch EC2 instances. Both are HashiCorp tools and complement each other.
Yes. Packer has an Ansible provisioner that runs playbooks inside the temporary build instance. This lets teams reuse existing Ansible roles for image building without rewriting them as shell scripts.
Yes. You can define multiple sources in a single build block and Packer builds them in parallel. This is useful for creating identical images across AWS, GCP, and Docker simultaneously.
Packer supports both HCL (HashiCorp Configuration Language) and JSON templates. HCL is the recommended format since Packer 1.7, offering better readability, variables, and expressions. JSON templates are considered legacy but still supported.
Sources citées (3)
- Packer GitHub— Packer creates identical machine images across multiple platforms
- Packer Documentation— HCL template format and plugin system for Packer
- HashiCorp Learn— Immutable infrastructure pattern for reducing configuration drift
En lien sur TokRepo
Fil de discussion
Actifs similaires
H2O-3 — Scalable Open-Source Machine Learning Platform
An in-memory distributed machine learning platform with AutoML support, offering gradient boosting, deep learning, GLM, and more through Python, R, and Java APIs.
Kubeflow — Machine Learning Toolkit for Kubernetes
An open-source platform for deploying, orchestrating, and managing ML workflows on Kubernetes. Kubeflow brings portable and scalable machine learning pipelines, notebook servers, model training, and serving to any Kubernetes cluster.
SHAP — Explain Any Machine Learning Model
Game-theoretic approach to explain the output of any machine learning model using Shapley values from cooperative game theory.
Watchtower — Automated Docker Container Image Updates
Runs as a container itself, polls registries for new image tags, and gracefully redeploys running containers when updates appear.