How to unzip zip file in rhel7 docker build environment - unzip command not found though its in OS

As part of a docker build, I have a line in the script like so:

RUN unzip myzipfile.zip

On that line in the script, it is failing with the following error:

/bin/sh: unzip: command not found

This is on Red Hat Enterprise Linux 7, and the base Docker image is also an RHEL7 base image.

If the unzip utility is not present in the Docker build environment, then how do I unzip something? unzip is present on the server that is doing the build, though I suppose that doesn't help. Is there an alternate utility that I should check for that can unzip files, or does unzip need to be installed in the base image?

If there is any way to do this without needing to install anything, that would be preferable, as I don't think I have permission to do that, and even if I did, the server that the Docker build happens on is not connected to the internet.

You have to install unzip with yum install unzip. If you don't want unzip to be in the final image, you have a few options:

  1. If the file comes from the build machine, you can unpack it there first.
  2. If the file comes from the build machine and you can change it, repack it as tar.gz and use ADD myfile.tar.gz /some/folder and Docker will automatically unpack it there.
  3. Use multistage build to install unzip, prepare the files, and then copy the files in the second stage.

    FROM registry.access.redhat.com/rhel7/rhel AS builder
    RUN yum install unzip
    ADD myfile.zip /dist
    RUN cd /dist && unzip myfile.zip && rm myfile.zip
    
    FROM registry.access.redhat.com/rhel7/rhel
    COPY --from=builder /dist/ /target