大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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, …

问题原文

原帖链接 · 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:

  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
    

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。