首页 > 解决方案 > 在 dockerfile [解决] 中将 .zip 转换为 tar.gz

问题描述

我得到了下载 .zip 文件夹的 dockerfile,因为 docker 容器没有apt-get。我无法解压缩它,但似乎 .tar.gz convert 嵌入在 dockerfile 中。

如何在 dockerfile 中将 .zip 转换为 .tar.gz?

有什么选择吗?gunzip 也不起作用。

somezipfile.zip has more than one entry -- unchanged

Dockerfile 部分

RUN curl -LJO http://somelink.com/verynew_python.zip

RUN gunzip -S .zip verynew_python.zip
ADD verynew_python.tar.gz /usr/bin
RUN chmod +x  /usr/bin/verynew_python/bin/python3.7

抱歉,我无法发布所有 dockerfile,但这是重要的部分。我想让python3.7作为主要的python ..也没有wget。

标签: dockerdockerfile

解决方案


您可以在您的 docker 容器中安装软件包 - 如果您可以自由选择这样的作品:

RUN apk add --no-cache unzip

WORKDIR /tmp
COPY testfile.zip .
RUN unzip testfile.zip
RUN rm testfile.zip
RUN tar czvf testfile.tgz *

这导致:

$ docker run -ti x sh
/tmp # ls
testfile      testfile.tgz
/tmp #

这很不优雅,但很有效。如果您的基础映像来自 docker hub,您可以查找它是否构建在发行版上,如果是,则为它选择“正确”的包管理器 - 最常见的是apkyumapt.

请记住 - 为了保持图像小 - 包缓存通常不可用,您需要apt update像上面一样获取它们或必须使用非缓存方法。


推荐阅读