What is Packer?

Packer is an open-source tool from HashiCorp that automates the creation of machine images.
Think of it as a “factory” that takes a base image (Ubuntu, CentOS, Windows) and produces consistent, pre-configured VM or cloud images ready for deployment.

Instead of manually preparing servers or VMs, you define everything in a template, and Packer does the work.


Key Features

  • Multi-platform builds — Create images for AWS AMI, Azure, Google Cloud, VMware, VirtualBox, Docker, and more, all at once.
  • Immutable infrastructure — Instead of configuring servers after they start, you ship pre-baked images.
  • Automation-friendly — Works well with CI/CD pipelines.
  • Extensible — Supports plugins for provisioners (e.g., Ansible, Chef, Puppet, shell scripts).

Example: Simple Packer Template

{
  "builders": [{
    "type": "docker",
    "image": "ubuntu:20.04",
    "commit": true
  }],
  "provisioners": [{
    "type": "shell",
    "inline": ["apt-get update", "apt-get install -y nginx"]
  }]
}

What happens here:

  1. Start with ubuntu:20.04 Docker image.
  2. Run provisioning (install Nginx).
  3. Save the result as a new Docker image.

When to Use Packer

  • Building goldeggn images for production (with pre-installed dependencies).
  • Standardizing environments across multiple clouds.
  • Speeding up autoscaling by using pre-baked images.

Conclusion

Packer helps developers and DevOps engineers avoid “snowflake servers” and instead work with predictable, automated images. If your infrastructure spans multiple platforms, Packer is a great way to keep things consistent.