问题原文
原帖链接 · Loduwijk · CC BY-SA 4.0
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.
已采纳解答
原帖链接 · kichik · CC BY-SA 4.0
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:
- If the file comes from the build machine, you can unpack it there first.
- If the file comes from the build machine and you can change it, repack it as
tar.gzand useADD myfile.tar.gz /some/folderand Docker will automatically unpack it there. 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
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
