Docker image ID changes (nearly) each build - and changes back

Hi,

I have a build script, that via docker build builds an image, based on node.

For some reason, if I execute docker build multiple times, the image ID changes and changes back to the first value - it’s not really a toggle. Mostly I receive the same ID a couple of times, then it changes. And in subsquent calls to docker build it changes back. Only changing between two values.

I could not find any difference between images, both manually unpacking as well as by container_diff.

I’d like to know why it changes and, especially, how I can prevent that. This contradicts reproducable builds and it disturbs my private registry, because it thinks one of the two image digests could be removed.

Here’s a simple log that demonstrates the behaviour:

> docker build --build-arg "SRV_BASE_IMAGE=node:18.16.0-alpine3.17" <context> --tag repo:5000/scope/server:latest
[+] Building 0.0s (8/8) FINISHED
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 86B                                                                                                                                                                              0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 762B                                                                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/node:18.16.0-alpine3.17                                                                                                                                    0.0s
 => [1/3] FROM docker.io/library/node:18.16.0-alpine3.17                                                                                                                                                      0.0s
 => [internal] load build context                                                                                                                                                                             0.0s
 => => transferring context: 64.43kB                                                                                                                                                                          0.0s
 => CACHED [2/3] WORKDIR /usr/src/app                                                                                                                                                                         0.0s
 => CACHED [3/3] COPY --chown=node:node . .                                                                                                                                                                   0.0s
 => exporting to image                                                                                                                                                                                        0.0s
 => => exporting layers                                                                                                                                                                                       0.0s
 => => writing image sha256:6a621cd3c6f3bd7bdc304f823698f9233c4667ab6956c551a534e5c343a37dd4                                                                                                                  0.0s
 => => naming to repo:5000/scope/server:latest                                                                                                                                                                0.0s

> docker build --build-arg "SRV_BASE_IMAGE=node:18.16.0-alpine3.17" <context> --tag repo:5000/scope/server:latest
[+] Building 0.0s (8/8) FINISHED
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 86B                                                                                                                                                                              0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 762B                                                                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/node:18.16.0-alpine3.17                                                                                                                                    0.0s
 => [1/3] FROM docker.io/library/node:18.16.0-alpine3.17                                                                                                                                                      0.0s
 => [internal] load build context                                                                                                                                                                             0.0s
 => => transferring context: 64.43kB                                                                                                                                                                          0.0s
 => CACHED [2/3] WORKDIR /usr/src/app                                                                                                                                                                         0.0s
 => CACHED [3/3] COPY --chown=node:node . .                                                                                                                                                                   0.0s
 => exporting to image                                                                                                                                                                                        0.0s
 => => exporting layers                                                                                                                                                                                       0.0s
 => => writing image sha256:5060c9b7c4ea32e55d9692a275f32ff5120ad6fb303f4eb5302608ccb8397b4a                                                                                                                  0.0s
 => => naming to repo:5000/scope/server:latest                                                                                                                                                                0.0s

> docker build --build-arg "SRV_BASE_IMAGE=node:18.16.0-alpine3.17" <context> --tag repo:5000/scope/server:latest
[+] Building 0.0s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 762B                                                                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 86B                                                                                                                                                                              0.0s
 => [internal] load metadata for docker.io/library/node:18.16.0-alpine3.17                                                                                                                                    0.0s
 => [1/3] FROM docker.io/library/node:18.16.0-alpine3.17                                                                                                                                                      0.0s
 => [internal] load build context                                                                                                                                                                             0.0s
 => => transferring context: 64.43kB                                                                                                                                                                          0.0s
 => CACHED [2/3] WORKDIR /usr/src/app                                                                                                                                                                         0.0s
 => CACHED [3/3] COPY --chown=node:node . .                                                                                                                                                                   0.0s
 => exporting to image                                                                                                                                                                                        0.0s
 => => exporting layers                                                                                                                                                                                       0.0s
 => => writing image sha256:6a621cd3c6f3bd7bdc304f823698f9233c4667ab6956c551a534e5c343a37dd4                                                                                                                  0.0s
 => => naming to repo:5000/scope/server:latest                                                                                                                                                                0.0s

Any idea?
Thanks!