Search code examples
spring-bootkuberneteskaniko

SpringBoot's bootBuildImage with Kaniko instead of a Docker daemon


SpringBoot 2.3 introduced a feature to create OCI/Docker images by running ./gradlew bootBuildImage instead of having a Dockerfile and execute docker build .

When building on a Gitlab build server that is running inside a Kubernetes cluster there is no Docker daemon available though (no docker-in-docker service for security reasons). Instead images have to be build and uploaded using Google's "Kaniko" tool.

Is it possible to combine both somehow i.e. use "bootBuildImage" without a running Docker daemon?


Solution

  • It is possible by using Podman. Podman includes a daemon that implements a Docker-compatible API. On a local machine this can be started via podman system service --time 0 tcp://0.0.0.0:2375.

    When running in Kubernetes (or generally in a container) you can use the container image from Quay: quay.io/containers/podman. Start the service in the background and the run your build. Something like this should work:

    build:
      image: my-java-builder
      services:
        - name: quay.io/containers/podman:v4.2.1
          alias: docker
          command: ["podman", "system", "service", "--time=0", "tcp://0.0.0.0:2375"]
      variables:
        DOCKER_HOST: tcp://docker:2375
      script:
        - ./gradlew bootBuildImage