buildx: BUILDKIT ignores "insecure-registries". server gave HTTP response to HTTPS client. x509: certificate error
Hello! After upgrading to Docker Engine v23.0.1 our CI process started failing due to errors accessing internal Harbor registry. As I see BuildKit became default in versions 23+.
Unfortunately Docker BuildKit disregards configuration insecure-registries in /etc/docker/daemon.json.
All attempts to build image fail with the following errors. Needless to say that address of our Harbor registry was added to insecure-registries. It used to work normally with previous versions of Docker.
Error getting v2 registry: Get \"https://harbor.company.local/v2/\/": http: server gave HTTP response to HTTPS client"
ERROR: failed to solve: harbor.company.local/hub/library/node:16.17.0-alpine3.16: failed to do request: Head "https://harbor.company.local/v2/hub/library/node/manifests/16.17.0-alpine3.16":
x509: certificate is valid for ingress.local, not harbor.company.local
/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
If we place commands like
docker pull harbor.company.local/hub/library/node:16.17.0-alpine3.16`
before docker build, all images are pulled successfully, which is proves that docker daemon is configured correctly and all other processes keep working.
Thanks to the discussion in #1613, we managed to implement a workaround with setting BUILDKIT_NO_CLIENT_TOKEN=true. š
For the sake of completeness, I have to mention another issue #1589, which is related to the same or very similar problem I believe.
Another workaround was to export DOCKER_BUILDKIT=0.
When this variable is set, the following message appear in the logs, which is expected, Iām convinced.
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0 environment-variable.
Anyway, we still shall appreciate if you can fix this behaviour and make BuildKit rely on insecure-registries in /etc/docker/daemon.json.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 24
- Comments: 37 (9 by maintainers)
To anyone coming across this in the future - this issue should now be resolved by https://github.com/moby/moby/pull/45992, which will be released as part of moby 25.0.
It seems to be broken again with v27.3.1
The last report from the maintainers here was that they couldnāt reproduce the specific error (only related ones), so itās not exactly fair to characterize them as not caring about it; theyāre a fairly busy team and likely just havenāt had a chance to get back to this yet and try to reproduce again. š ā¤ļø
This happens to be something I ran into recently, so I was able to get the same error with the following minimal reproducer for the two related problems here (insecure-registry from Docker not applying to BuildKit and insecure registry-mirror from Docker in BuildKit): š
Failing Output:
Itās noted in some of the previous comments, and itās not mentioned on https://docs.docker.com/engine/reference/commandline/dockerd/#insecure-registries, but https://docs.docker.com/registry/insecure/ does suggest that
insecure-registrycan also accept a protocol, presumably as a way to differentiate between āuse TLS, but accept an insecure certificateā vs āuse the insecure HTTP protocolā thatinsecure-registryotherwise technically means ābothā of (as seen by Docker itself not needing a protocol specified; cc @thaJeztah @neersighted @dvdksn, maybe something to document more consistently?)When I update
--insecure-registryto include thehttp://prefix (dockerd --insecure-registry http://foo-registry:5000 --registry-mirror http://foo-registry:5000), this example does work for me, and gets all the way through both builds successfully. šSuccessful Output:
Iām not sure why the example above with
daemon.jsonshowing the same configuration didnāt work, but maybe worth testing again and being certain both flags/config values includehttp://explicitly?(There is arguably a bug here where BuildKit is interpreting Dockerās configuration in a slightly different way from Docker itself, but itās not unfair for BuildKit to have not wanted to implement the same āwhich type of insecure?ā heuristic as Docker did because it is not the most reliable/efficient thing to try and detect correctly, which is why I think this might be more of a documentation issue since Docker doesnāt mind the protocol prefix and BuildKit works correctly with it. š )
To highlight from @tianon 's comment:
If you hit this error with
insecure-registries: check if you have defined protocol in the URL.http://if the insecure server is using plain HTTP andhttps://if server is using self-signed certificates with TLS. If you still hit an issue, we need extra information about the case and the exact versions, ideally a runnable reproducer.Oh, I didnāt know it. Now I do. Thank you!
Hey @jedevc, I just tried docker 25 and when using in dind (started with both
--registry-mirrorand--insecure-registry) (docker:25-dind) + docker buildx in a separate container (docker:25) connecting to dind for the daemon and it does not seem to work at all, the registry mirror is simply ignored when IĀ look at the debug logs of buildx.Is this meant to work following your change or am I confused about all of this?
Some versioning information:
I see also a dependency to buidkit when building:
The only way IĀ found to make it work is to use the following buildkit.toml passed to
docker buildx create --config buildkit.tomlSo as it turns out, apparently using
httpandhttpsininsecure-registriesis deprecated? https://github.com/moby/moby/pull/29988, I think we want a docs update in https://docs.docker.com/registry/insecure/ to reflect this?Also, apparently
insecure-registriessupports CIDR notation - I havenāt seen this a lot in the wild, but I imagine we probably want to support this case as well for containerd/buildkit (looks like the new containerd snapshotter and buildkit share the same codepath here).