Docker builder leaves /packer-files in the new image

I use the Packer Docker builder to create a simple Docker image and noticed that it leaves the mount point of the host volume mount (/packer-files) in the image. I realize the host directory has restrictive permissions, likely to share secure information in the container, but there is no use for the mount point after the image is created.

I have a simple example in bruno-packer/simple1 at main · pfuntner/bruno-packer · GitHub

$ cd simple1
$ packer build simple1.pkr.hcl
docker.simple1: output will be in this color.

==> docker.simple1: Creating a temporary directory for sharing data...
==> docker.simple1: Pulling Docker image: ubuntu:latest
    docker.simple1: latest: Pulling from library/ubuntu
    docker.simple1: Digest: sha256:27cb6e6ccef575a4698b66f5de06c7ecd61589132d5a91d098f7f3f9285415a9
    docker.simple1: Status: Image is up to date for ubuntu:latest
==> docker.simple1: Starting docker container...
    docker.simple1: Run command: docker run -v /home/ubuntu/.config/packer/tmp3941861951:/packer-files -d -i -t --entrypoint=/bin/sh -- ubuntu:latest
    docker.simple1: Container ID: 7bc41d246591646c0d6c862fe33cce329f695b3f42c797f92dd76e9fe6a6222b
==> docker.simple1: Using docker communicator to connect:
==> docker.simple1: Provisioning with shell script: /tmp/packer-shell999041850
==> docker.simple1: Committing the container
    docker.simple1: Image ID: sha256:1b5a62e69852bced6035ca8de430530787eb68e95ca6dea9c5e6f6cf58f300b9
==> docker.simple1: Killing the container: 7bc41d246591646c0d6c862fe33cce329f695b3f42c797f92dd76e9fe6a6222b
==> docker.simple1: Running post-processor:  (type docker-tag)
    docker.simple1 (docker-tag): Tagging image: sha256:1b5a62e69852bced6035ca8de430530787eb68e95ca6dea9c5e6f6cf58f300b9
    docker.simple1 (docker-tag): Repository: simple1:latest
Build 'docker.simple1' finished after 2 seconds 922 milliseconds.

==> Wait completed after 2 seconds 922 milliseconds

==> Builds finished. The artifacts of successful builds are:
--> docker.simple1: Imported Docker image: sha256:1b5a62e69852bced6035ca8de430530787eb68e95ca6dea9c5e6f6cf58f300b9
--> docker.simple1: Imported Docker image: simple1:latest with tags simple1:latest
$ docker run -it --rm simple1:latest
# ls -ld /packer-files
drwxr-xr-x 2 root root 4096 Dec 22 12:07 /packer-files
# find /packer-files

I’m using:

  • Packer 1.8.4
  • Docker 20.10.12
  • Host OS: Ubuntu 20

Does anyone have an idea of how to get rid of the mount point without creating yet another image?