7

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?

lathspell
  • 3,040
  • 1
  • 30
  • 49
  • What do you mean by 'combine both'? You want to somehow use Kaniko instead of a local Docker Daemon? – Wytrzymały Wiktor Apr 29 '20 at 09:42
  • Yes, exactly. Or maybe, if SpringBoot creates a `Dockerfile` and then calls Docker, have it write the Dockerfile and then stop so that I can use Kaniko to actually build the Image. – lathspell Apr 29 '20 at 11:13
  • I don't think that would be possible. See https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/gradle-plugin/reference/html/#build-image-docker-daemon. – FizzyTidus Jun 03 '20 at 03:36

2 Answers2

1

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
derkoe
  • 5,649
  • 2
  • 23
  • 31
-1

Derkoe, should be: command: ["podman", "system", "service", "--time=0", "tcp://0.0.0.0:2375"]

Besides, running the previous solution with Maven: mvn spring-boot:build-image -e, I got the error:

[INFO]  > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 0%
[INFO]  > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 0%
[INFO]  > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 100%
[INFO]  > Pulled builder image 'docker.io/paketobuildpacks/builder@sha256:55c9883c40ff9f3a41e6db168266b7b21d04b5e63bbde99c9976f1d7458f7153'
[INFO]  > Pulling run image 'docker.io/paketobuildpacks/run:tiny-cnb' 100%
[INFO]  > Pulled run image 'docker.io/paketobuildpacks/run@sha256:11d6196c9185cbb5eff12410ebc14ad5a19edc6553329b5d3d2ae7a95ed723f9'
[INFO]  > Executing lifecycle version v0.16.0
[INFO]  > Using build cache volume 'pack-cache-1faddfe7a378.build'
[INFO] 
[INFO]  > Running creator
[INFO]     [creator]     ERROR: failed to initialize docker client: failed to connect to docker socket: dial unix /var/run/docker.sock: connect: connection refused
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Any idea?

  • Adding `true` according to [spring-boot-maven-plugin docs](https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#build-image.examples.docker.podman) fixes my problem – Paulo Pérez Prieto Feb 23 '23 at 23:14