Skip to content

Conversation

@krjakbrjak
Copy link

This PR introduces a new build_only option to the Docker builder. When enabled, Packer will:

  • Only execute the build block (equivalent to running docker build)
  • Skip running any provisioners
  • Avoid mounting the /packer-files directory into the container

Currently, Packer always mounts a host directory at /packer-files for provisioners. This directory is:

  • Unmountable post-build (due to Docker limitations)
  • Persisted in the final image, even if empty
  • Not needed if provisioners aren’t used

This causes unnecessary artifacts in images and complicates reproducible builds. This issue is described in #134.

Benefits

  • Cleaner final Docker images (no /packer-files directory)
  • Improved reproducibility: image hashes remain stable for identical manifests
  • More predictable builds for CI/CD pipelines using Docker-native workflows

Example usage:

source "docker" "postgres" {
  build {
    path = "Dockerfile"
  }
  build_only = true
  commit     = true
}

@krjakbrjak krjakbrjak requested a review from a team as a code owner July 22, 2025 08:37
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Jul 22, 2025

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Signed-off-by: Nikita Vakula <programmistov.programmist@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant