How use `export_path` as well as `docker-import` in the same packer file for Docker Builder?

In the Packer Docker Builder, whenever there exists export_path parameter, it does not save the docker container (exports it) to a tar file when in the build section there exists a post-processor docker-import.

Is there a way to build the docker container but also save the filesystem as a tar ball, and have that container as an image for later usage?

The solution is to use the keep_input_artifact = true in the post-processor docker-import.

Example:


source "docker" "micropi" {
  image = "ubuntu:focal"
  discard = false
  platform = "linux/arm64/v8"
  export_path = "./ubuntu-arm64-focal.tar"
}

build {
  name = "step1"
  sources = [ "source.docker.micropi" ]

  provisioner "shell" {
    inline = [
      "apt-get update",
      "apt-get install -y --no-install-recommends linux-image-raspi",
      "apt-get install -y --no-install-recommends systemd-sysv"
    ]
  }
  post-processor "docker-import" {
    repository = "local/micropi-armv8"
    tag = "0.0.1"
    keep_input_artifact = true
  }
}