Docker缓存导致误报释放

Bar*_*baz 2 caching apt docker

我有以下 dockerfile:

\n
FROM debian:buster\n\n#Configure apt to look at my Debian repository\nCOPY ./apt /etc/apt\n\n#Install the software into the image\n\nRUN 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\n\nENTRYPOINT ["/usr/sbin/main.sh"]\nCMD []\n
Run Code Online (Sandbox Code Playgroud)\n

所以基本上它从版本 1.1-0 安装包 \xe2\x80\x9cbusiness\xe2\x80\x9d\n我的 docker 缓存有问题,我\xe2\x80\x99m 推送包 \xe2\x80\ 的新代码更改x9cbusiness\xe2\x80\x9d 具有相同版本 (1.1-0) [是的,我\xe2\x80\x99m 覆盖版本\xe2\x80\xa6] 并且 docker 缓存不够智能,无法提取新更改的 .deb。

\n

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

\n

有办法解决吗?我可以仅从特定层构建而不使用缓存吗?

\n

小智 5

是的你可以,

选项a)

  • 分割你的 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
    
    Run Code Online (Sandbox Code Playgroud)

选项b)

  • 使用多阶段构建,但使用 和--no-cache选项生成第二个映像 (例如,在第一个管道中进行升级,作为 someimage:baseimage 推送,然后在下一阶段使用docker-composedocker buildFROM someimage:baseimage

选项c)

  • 我期望得到的理想答案类型是让 docker 缓存更加智能,并弄清楚二进制文件本身是否已更改,但版本没有更改,但这似乎是不可能的,并且是 Docker 想要的/有意的行为(有假设版本没有被覆盖,并且没有机会在不下载的情况下验证二进制文件)所以我会接受你的答案:-) (2认同)