【发布时间】:2021-01-18 12:59:43
【问题描述】:
我从以前的同事那里继承了一个基本映像。我只有图像,没有与之对应的dockerfile。图像是下面的名称“c1829df3bbea”。当我运行这个命令时,我看到它有 167 层:
docker history c1829df3bbea | wc -l
现在一些公司配置发生了变化,需要我向图像中添加一些新文件。我在下面创建了 Dockerfile,它使用原始图像作为基础层:
FROM rbc/pmcs/dna_prod:latest
USER root
# Copy the run script to the docker container
COPY bin/run.sh $PMCS_HOME/run.sh
# Now copy in the most recent hadoop config files, as required by the migration to Range KMS on Saturday Sep 26 2020
COPY edlhp1-config/edlhp1/hadoop /app/hadoop_conf/strprod/hadoop
# Update the security certificates to the most recent versions
RUN cd /etc/pki/ca-trust/source/anchors && curl --insecure -O https://webapps4.fg.rbc.com/WLM0/Forms/Help/Production_RBC_G2_Root_CA.cer && curl --insecure -O https://webapps4.fg.rbc.com/WLM0/Forms/Help/Production_RBC_G2_Intermediate_CA.cer && update-ca-trust extract && ls /etc/pki/ca-trust/source/anchors && update-ca-trust force enable && update-ca-trust extract && chmod 755 $PMCS_HOME/run.sh
USER $USER
然后我使用命令重建:
docker build . --tag rbc/pmcs/prod:1.2
它可以加载 6 个步骤中的 5 个,但在最后一步失败,并显示消息“超出最大深度”。
我意识到可以做一些事情来减少层数,例如组合运行语句,以及使复制语句一次移动多个文件。请假设这已尽可能地完成。我想知道当我无法访问用于构建基础镜像的 Dockerfile 时,是否有办法减少基础镜像中的层数。
【问题讨论】:
-
我不知道,但this question 可能有一些工具可以帮助您解决问题。
-
您可以尝试修剪悬挂的容器和图像:
docker container prune和docker image prune(来自 stackoverflow.com/a/61824081/5666087) -
@jakub 不会对具有太多层的基础图像产生影响。
-
恐怕你已经发现了没有 Dockerfile 和源来构建镜像的问题。现在最好的方法是创建该 Dockerfile 并替换该基础映像。
标签: docker