Home > Back-end >  Use Spring Native with custom Docker registry
Use Spring Native with custom Docker registry

Time:05-05

We're experimenting with Spring Native, following their guide. Additionally, we wish use Gradle and Buildpacks. We have adapted our configuration (build.gradle) accordingly and run ./gradlew bootBuildImage in order to build the Spring Native image.

The problem arises because we are forced to use the custom Docker image registry of our company. Therefore, we can't directly pull e. g. docker.io/paketobuildpacks/run:tiny-cnb, but have to use something like docker-io.docker-proxy.ourcompany.com/paketobuildpacks/run:tiny-cnb.

We have already pulled and re-tagged the builder image paketobuildpacks/builder used during the process. But as the rest is happening inside this build container, we cannot use this solution any further. So we get:

* What went wrong:
Execution failed for task ':bootBuildImage'.
> Docker API call to 'localhost/v1.24/images/create?fromImage=docker.io/paketobuildpacks/run:tiny-cnb' failed with status code 500 "Internal Server Error" and message "Get "https://registry-1.docker.io/v2/": context deadline exceeded"

(Probably because a connection attempt to *.docker.io will just time out.)

As of the moment, we have not found a possibility to configure the Docker registry used by the process. We could also find a bigger "tree" of further dependencies needed later during the process, described in files like here (where gcr.io is referred instead of docker.io).

In no way will we be allowed to access the public registries directly and thus have no further ideas. So, can you think of any sane possibility to achieve our goal of building the Spring Native image using your our own proxy registries?

Many thanks in advance!

CodePudding user response:

With the pack cli, you can run pack config registry-mirrors add <registry> [-m <mirror...] [flags], ex: pack config registry-mirrors add index.docker.io --mirror 10.0.0.1 where 10.0.0.1 is your private registry.

https://buildpacks.io/docs/tools/pack/cli/pack_config_registry-mirrors_add/

In Spring Boot's Gradle support you have the docker.builderRegistry and docker.publishRegistry settings, but these are primarily used to supply credentials to be used to fetch or publish images from the registry. They do not quite do what we need here.

https://docs.spring.io/spring-boot/docs/2.6.7/gradle-plugin/reference/htmlsingle/#build-image.docker-registry

Support for mirror functionality, like with pack cli, isn't presently an option. An issue has been opened to track support for this, so hopefully it'll be available in a future release.

In the meantime, you can use pack cli with the mirror option above to build images.

A quick way to test/validate:

  1. Run docker run -d -p 5000:5000 --restart=always --name=registry -e REGISTRY_PROXY_REMOTEURL=https://registry-1.docker.io registry:2. This will run a local registry that mirrors Docker Hub.

  2. Run pack config registry-mirrors add '*' --mirror localhost:5000 to tell pack cli to use the registry mirror.

  3. Run pack build against your app. You should see output like:

Using mirror localhost:5000/paketobuildpacks/builder:base for index.docker.io/paketobuildpacks/builder:base
base: Pulling from paketobuildpacks/builder
83525de54a98: Pulling fs layer
807f554cf05f: Pulling fs layer
...

If you see that line, you know it's working properly.

You should also see this in your pack config:

> cat ~/.pack/config.toml
[registry-mirrors]
  "*" = "localhost:5000"

That means you've got the registry mirror set up correctly.

  • Related