Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker with BuildKit uses the wrong cache #16

Open
enasca opened this issue Apr 4, 2023 · 1 comment · May be fixed by #17
Open

Docker with BuildKit uses the wrong cache #16

enasca opened this issue Apr 4, 2023 · 1 comment · May be fixed by #17

Comments

@enasca
Copy link

enasca commented Apr 4, 2023

moby/buildkit#1368

There are two Dockerfiles with the same size and timestamp in this repository:

This triggers a subtle bug in BuildKit whereby the same base image is used for both builds. As a result, one image with two tags is produced instead of two different images. The build completes successfully, then one of the two container fails to run when deployed.

This is apparently fixed in Docker Engine 23 (moby/buildkit#1368). I haven't verified. I simply worked around it by disabling BuildKit. Perhaps a check could be added to the build scripts to disable BuildKit if Docker is not recent enough.

@enasca
Copy link
Author

enasca commented Apr 5, 2023

Docker Engine v23 indeed fixes the issue.

Reproduction steps for Docker v20:

$ docker version
Client: Docker Engine - Community
 Version:           20.10.24
 API version:       1.41
 Go version:        go1.19.7
 Git commit:        297e128
 Built:             Tue Apr  4 18:21:00 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
[...]

$ docker builder prune -a
WARNING! This will remove all build cache. Are you sure you want to continue? [y/N] y

# Build alert-manager.
$ pushd kaapana/services/monitoring/alert-manager/docker
$ DOCKER_BUILDKIT=1 docker build -t local/alertmanager .
[+] Building 3.0s (5/5) FINISHED                                                                                                                                                                
 => [internal] load build definition from Dockerfile                                                                                                                                       0.0s
 => => transferring dockerfile: 160B                                                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                                            0.0s
 => [internal] load metadata for docker.io/prom/alertmanager:v0.25.0                                                                                                                       1.1s
 => [1/1] FROM docker.io/prom/alertmanager:v0.25.0@sha256:fd4d9a3dd1fd0125108417be21be917f19cc76262347086509a0d43f29b80e98                                                                 1.8s
[...]
 => => writing image sha256:1b8c7fce1ec13b79dbc4a891a82025174aab7963a3e368d30eadb5aab6e2a1cd                                                                                               0.0s

$ popd

# Build node-exporter. Observe that the base image from alertmanager is used.
$ pushd kaapana/services/monitoring/node-exporter/docker
$ DOCKER_BUILDKIT=1 docker build -t local/nodeexporter .
[+] Building 0.8s (5/5) FINISHED                                                                                                                                                                
 => [internal] load build definition from Dockerfile                                                                                                                                       0.0s
 => => transferring dockerfile: 37B                                                                                                                                                        0.0s
 => [internal] load .dockerignore                                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                                            0.0s
 => [internal] load metadata for docker.io/prom/alertmanager:v0.25.0                                                                                                                       0.7s
 => CACHED [1/1] FROM docker.io/prom/alertmanager:v0.25.0@sha256:fd4d9a3dd1fd0125108417be21be917f19cc76262347086509a0d43f29b80e98                                                          0.0s
 => exporting to image                                                                                                                                                                     0.0s
 => => exporting layers                                                                                                                                                                    0.0s
 => => writing image sha256:1b8c7fce1ec13b79dbc4a891a82025174aab7963a3e368d30eadb5aab6e2a1cd                                                                                               0.0s

@enasca enasca linked a pull request Apr 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant