I’m running in a hell since I try to avoid deploying some unchanged container, and want to use the digest to detect an image is the same … but I can’t have those digest to be the same.
I’m building a dotnet app, out of the container, then I COPY this app and dependencies in the container in order to ship & deploy it.
This is the dockerfile, obviously the ARGuments sent are exactly the same
ARG RUNTIME_IMAGE
FROM $RUNTIME_IMAGE AS final
COPY . /app/.
EXPOSE 80
ARG PROJECT_NAME
ENV RUN_PROJECT_NAME=$PROJECT_NAME
ENTRYPOINT dotnet $RUN_PROJECT_NAME.dll
Already verified :
the binaries are exactly the same (used container-diff to check this topic, then compared files from extracted folders in a diff/merged tool, i’m 100% sure)
Also set always same the creation/access/write time of the files and directories copied
Also set always same the creation/access/write time of the dockerfile itself
The image
TAG IMAGE ID CREATED SIZE
test11 sha256:74b1558ea77c84bf980281082719973a6d14b1eed24c23d434e589bb5b77db4e 2 seconds ago 279MB
test10 sha256:2e8de287b201c415aa87fb4c06de95727d5e4474bc54c5ecfbf8e1697635e795 About a minute ago 279MB
Each time you build an image, at least the metadata that stores the create data for each image layer will differ. Seems like the digiest is not only calculated based on the payload itself…
See for yourself:
– docker save test10 > test10.tar
– docker save test11 > test11.tar
Extract both tar files to a distinct folder to unwrapp the image layer. Take a look at those files.
Buy using a multistage build and tricking the /app folder time, I finally have the layer.tar file exactly identicall between two builds. Now the layer manisfest json file is different because it brings a creation date with itself … does it use this date to compute the digest hash ?
The changes in the manifest.json were the only differences i could spot when building the same image two times in a row. Without taking a look at the sources, this will only remain guessing…
Ok, by some tricks I finally managed to have the layers digests to be the same :
create all the files in an app folder
then touch all files in the host to have the exact always same dates
then COPY . .
I can now compare the layers digests and detect them to be the same, while the full image manifest is still differente, it’s enough for my needs today.