Packer: Unable to use packer with distroless base images

Created on 17 Sep 2019  ยท  5Comments  ยท  Source: hashicorp/packer

I would like to use packer with the google distroless images, but I'm unclear on how this could work.

This is essentially the configuration I'm trying to use, along with postprocessors.

{
  "builders": [{
    "type": "docker",
    "image": "gcr.io/distroless/static",
    "commit": true,
    "changes": [
      "ENTRYPOINT [\"./app\"]"
    ],
  }],
  "provisioners": [
    {
      "type": "file",
      "source": "app",
      "destination": "."
    }
  ]
}

The main issue that I'm having is that these images don't include a shell, no /bin/sh and no /bin/bash. I don't know if it's possible to use a different run_command to get this to work. I wasn't able to with a couple attempts.

For the record you can find the repo for the distroless images here, https://github.com/GoogleContainerTools/distroless

buildedocker enhancement question

Most helpful comment

Yes, Packer will not work with any of the images such as scratch or true that are missing any type of shell.

The main point of building Docker images with Packer is because you want to build the "same" image for multiple target (such as an AMI and a Docker image). If you are building more minimal Docker Images you are better of using the Docker cli, tar, habitus, kaniko, makisu, etc.

All 5 comments

We definitely didn't consider when writing this builder that a Docker image would have no shell for Packer to access. That means the default entrypoint definitely won't work for you, and I suspect that a lot of other tooling won't either. You may have better luck reaching out to the mailing list or community forum, since the issue tracker is only read by maintainers rather than the larger community.

Yes, Packer will not work with any of the images such as scratch or true that are missing any type of shell.

The main point of building Docker images with Packer is because you want to build the "same" image for multiple target (such as an AMI and a Docker image). If you are building more minimal Docker Images you are better of using the Docker cli, tar, habitus, kaniko, makisu, etc.

Thanks for the input, I've used packer for other more complex docker images and I appreciate the declarative nature of the configuration. But this makes sense and I'm likely to go down the route of using the docker cli instead.

Yeah, I think working with these minimal images is probably outside of the scope of Packer. We're not likely to dedicated maintainer time to making Packer work with these minimal images, so I think I'm going to close this issue -- but if someone wants to tinker and can figure out how to make them work, we can update documentation in the future with a how-to guide.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings