Docker 缓存导致误报释放

问题描述 投票:0回答:1

我有以下 dockerfile:

FROM debian:buster

#Configure apt to look at my Debian repository
COPY ./apt /etc/apt

#Install the software into the image

RUN apt-get update && apt-get -V -y dist-upgrade && apt-get -V -y --allow-unauthenticated --no-install-recommends --allow-downgrades install -f business=1.1-0

ENTRYPOINT ["/usr/sbin/main.sh"]
CMD []

所以基本上它从版本 1.1-0 安装包“business” 我在使用 docker 缓存时遇到问题,我正在推动具有相同版本 (1.1-0) 的包“business”的新代码更改 [是的,我正在覆盖版本……] 并且 docker 缓存不够智能,无法提取新的改变了.deb.

它使用缓存层而无需我的代码更改:皱眉: 作为解决方法,我使用 --no-cache 进行构建,但我不喜欢这个解决方案,因为我正在失去缓存机制。

有什么办法解决吗?我可以只从特定层构建没有缓存吗?

docker caching apt
1个回答
1
投票

是的,你可以,

选项a)

  • split 你的 dockerfile ,在未缓存的命令中生成一个随机结果:
    RUN apt-get update && apt-get -V -y dist-upgrade 
    RUN head -c 23 /dev/urandom > /.randfile  && apt-get -V -y --allow-unauthenticated --no-install-recommends --allow-downgrades install -f business=1.1-0
    

选项b)

  • 使用多阶段构建, 但生成第二张图片
    --no-cache
    docker-compose
    docker build
    的选项 (例如,在第一个管道中进行升级,推送为 someimage:baseimage, 然后在下一阶段使用
    FROM someimage:baseimage

选项c)

© www.soinside.com 2019 - 2024. All rights reserved.