Issue in Building a Docker Image with Maven - spring-boot

I m trying to build docker image for springboot project using below command ,
./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=myorg/myapp
error ,
[INFO] > Using build cache volume 'pack-cache-152f93393a7f.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] Previous image with name "myorg/myapp:latest" not found
[INFO] [creator] ===> DETECTING
[INFO] [creator] qemu: uncaught target signal 11 (Segmentation fault) - core dumped
My machine details are:
macOsBigSur
Version - 11.2.2
Chip - Apple M1
RAM - 16 GB
Any suggestions ?

Related

spring boot maven plugin build-image is not working

I created demo project from start.spring.io with spring boot version 3.0.1 and java version 17.
I tried to execute below command on terminal to build Docker image
mvn spring-boot:build-image -Dspring-boot.build-image.imageName=testtesttest
It resulted in error
[INFO] [creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[INFO] [creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[INFO] [creator] Using Java version 18 extracted from MANIFEST.MF
[INFO] [creator] No valid JRE available, providing matching JDK instead. Using a JDK at runtime has security implications.
[INFO] [creator] : Contributing to layer
[INFO] [creator] Warning: Dependency has no SHA256. Skipping cache.
[INFO] [creator] Downloading from
[INFO] [creator] unable to invoke layer creator
[INFO] [creator] unable to get dependency
[INFO] [creator] unable to download
[INFO] [creator] unable to request
[INFO] [creator] Get "": unsupported protocol scheme ""
[INFO] [creator] ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.756 s
[INFO] Finished at: 2023-01-02T15:18:19+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:build-image (default-cli) on project demo: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:build-image failed: Builder lifecycle 'creator' failed with status code 51 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
I am using openjdk (version "18.0.2" 2022-07-19) on mac. Not able to figure it out. Can you please help.
Looks like the default image builder doesn't yet support Mac M1 processor. I had to add an alternative builder for maven plugin in my pom.xml as shown below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>dashaun/builder:tiny</builder>
</image>
</configuration>
</plugin>

spring-boot:build-image gets stuck

I want to test the new native-build feature of the spring boot 3.0 release. I am following this tutorial [here][1].
I installed jdk java 22.3.r17-nik via sdkman.
I ran $ mvn -Pnative spring-boot:build-image. The process starts but then always get stuck.
This is the log:
[INFO]
[INFO] -----------------------< com.example:myproject >------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:3.0.0:build-image (default-cli) > package # myproject >>>
[INFO]
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) # myproject ---
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) # myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) # myproject ---
[INFO] skip non existing resourceDirectory /Users/klaaspelzer/Projects/boot3/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) # myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # myproject ---
[INFO]
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) # myproject ---
[INFO] Building jar: /Users/klaaspelzer/Projects/boot3/target/myproject-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] <<< spring-boot-maven-plugin:3.0.0:build-image (default-cli) < package # myproject <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:3.0.0:build-image (default-cli) # myproject ---
[INFO] Building image 'docker.io/library/myproject:0.0.1-SNAPSHOT'
[INFO]
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 100%
[INFO] > Pulled builder image 'paketobuildpacks/builder#sha256:850b2b3dd3eab7bacfe33839712c67c3cb50431aff4ff36c435b3d97ea927268'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:tiny-cnb' 100%
[INFO] > Pulled run image 'paketobuildpacks/run#sha256:c6b81e85b32036dab113dc33454eaa29c006c252bb48a87bf623a635c1763ce6'
[INFO] > Executing lifecycle version v0.15.1
[INFO] > Using build cache volume 'pack-cache-eed8708d57f5.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ===> ANALYZING
[INFO] [creator] Previous image with name "docker.io/library/myproject:0.0.1-SNAPSHOT" not found
[INFO] [creator] ===> DETECTING
[INFO] [creator] 6 of 14 buildpacks participating
[INFO] [creator] paketo-buildpacks/ca-certificates 3.5.0
[INFO] [creator] paketo-buildpacks/bellsoft-liberica 9.10.0
[INFO] [creator] paketo-buildpacks/syft 1.22.1
[INFO] [creator] paketo-buildpacks/executable-jar 6.5.0
[INFO] [creator] paketo-buildpacks/spring-boot 5.20.0
[INFO] [creator] paketo-buildpacks/native-image 5.6.0
[INFO] [creator] ===> RESTORING
[INFO] [creator] ===> BUILDING
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for CA Certificates 3.5.0
[INFO] [creator] https://github.com/paketo-buildpacks/ca-certificates
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for BellSoft Liberica 9.10.0
[INFO] [creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_JVM_JLINK_ARGS --no-man-pages --no-header-files --strip-debug --compress=1 configure custom link arguments (--output must be omitted)
[INFO] [creator] $BP_JVM_JLINK_ENABLED false enables running jlink tool to generate custom JRE
[INFO] [creator] $BP_JVM_TYPE JRE the JVM type - JDK or JRE
[INFO] [creator] $BP_JVM_VERSION 11 the Java version
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_DEBUG_ENABLED false enables Java remote debugging support
[INFO] [creator] $BPL_DEBUG_PORT 8000 configure the remote debugging port
[INFO] [creator] $BPL_DEBUG_SUSPEND false configure whether to suspend execution until a debugger has attached
[INFO] [creator] $BPL_HEAP_DUMP_PATH write heap dumps on error to this path
[INFO] [creator] $BPL_JAVA_NMT_ENABLED true enables Java Native Memory Tracking (NMT)
[INFO] [creator] $BPL_JAVA_NMT_LEVEL summary configure level of NMT, summary or detail
[INFO] [creator] $BPL_JFR_ARGS configure custom Java Flight Recording (JFR) arguments
[INFO] [creator] $BPL_JFR_ENABLED false enables Java Flight Recording (JFR)
[INFO] [creator] $BPL_JMX_ENABLED false enables Java Management Extensions (JMX)
[INFO] [creator] $BPL_JMX_PORT 5000 configure the JMX port
[INFO] [creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[INFO] [creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[INFO] [creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[INFO] [creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[INFO] [creator] Using Java version 17 extracted from MANIFEST.MF
[INFO] [creator] BellSoft Liberica NIK 17.0.5: Contributing to layer
[INFO] [creator] Downloading from https://download.bell-sw.com/vm/22.3.0/bellsoft-liberica-vm-core-openjdk17.0.5+8-22.3.0+2-linux-amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Expanding to /layers/paketo-buildpacks_bellsoft-liberica/native-image-svm
[INFO] [creator] Adding 127 container CA certificates to JVM truststore
[INFO] [creator] Writing env.build/JAVA_HOME.override
[INFO] [creator] Writing env.build/JDK_HOME.override
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Syft 1.22.1
[INFO] [creator] https://github.com/paketo-buildpacks/syft
[INFO] [creator] Downloading from https://github.com/anchore/syft/releases/download/v0.60.3/syft_0.60.3_linux_amd64.tar.gz
[INFO] [creator] Verifying checksum
[INFO] [creator] Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Executable JAR 6.5.0
[INFO] [creator] https://github.com/paketo-buildpacks/executable-jar
[INFO] [creator] Class Path: Contributing to layer
[INFO] [creator] Writing env.build/CLASSPATH.delim
[INFO] [creator] Writing env.build/CLASSPATH.prepend
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Spring Boot 5.20.0
[INFO] [creator] https://github.com/paketo-buildpacks/spring-boot
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_SPRING_CLOUD_BINDINGS_DISABLED false whether to contribute Spring Boot cloud bindings support
[INFO] [creator] Launch Configuration:
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_DISABLED false whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] $BPL_SPRING_CLOUD_BINDINGS_ENABLED true Deprecated - whether to auto-configure Spring Boot environment properties from bindings
[INFO] [creator] Class Path: Contributing to layer
[INFO] [creator] Writing env.build/CLASSPATH.append
[INFO] [creator] Writing env.build/CLASSPATH.delim
[INFO] [creator] Image labels:
[INFO] [creator] org.opencontainers.image.title
[INFO] [creator] org.opencontainers.image.version
[INFO] [creator] org.springframework.boot.version
[INFO] [creator] Warning: BOM table is deprecated in this buildpack api version, though it remains supported for backwards compatibility. Buildpack authors should write BOM information to <layer>.sbom.<ext>, launch.sbom.<ext>, or build.sbom.<ext>.
[INFO] [creator]
[INFO] [creator] Paketo Buildpack for Native Image 5.6.0
[INFO] [creator] https://github.com/paketo-buildpacks/native-image
[INFO] [creator] Build Configuration:
[INFO] [creator] $BP_BINARY_COMPRESSION_METHOD Compression mechanism used to reduce binary size. Options: `none` (default), `upx` or `gzexe`
[INFO] [creator] $BP_NATIVE_IMAGE true enable native image build
[INFO] [creator] $BP_NATIVE_IMAGE_BUILD_ARGUMENTS arguments to pass to the native-image command
[INFO] [creator] $BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE a file with arguments to pass to the native-image command
[INFO] [creator] $BP_NATIVE_IMAGE_BUILT_ARTIFACT the built application artifact explicitly, required if building from a JAR
[INFO] [creator] Native Image: Contributing to layer
[INFO] [creator] Executing native-image -H:+StaticExecutableWithDynamicLibC -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.example.boot3.MyApplication -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/spring-boot-3.0.0.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-3.0.0.jar:/workspace/BOOT-INF/lib/logback-classic-1.4.5.jar:/workspace/BOOT-INF/lib/logback-core-1.4.5.jar:/workspace/BOOT-INF/lib/slf4j-api-2.0.4.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.19.0.jar:/workspace/BOOT-INF/lib/log4j-api-2.19.0.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-2.0.4.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar:/workspace/BOOT-INF/lib/spring-core-6.0.2.jar:/workspace/BOOT-INF/lib/spring-jcl-6.0.2.jar:/workspace/BOOT-INF/lib/snakeyaml-1.33.jar:/workspace/BOOT-INF/lib/jackson-databind-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-core-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.14.1.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.14.1.jar:/workspace/BOOT-INF/lib/tomcat-embed-core-10.1.1.jar:/workspace/BOOT-INF/lib/tomcat-embed-el-10.1.1.jar:/workspace/BOOT-INF/lib/tomcat-embed-websocket-10.1.1.jar:/workspace/BOOT-INF/lib/spring-web-6.0.2.jar:/workspace/BOOT-INF/lib/spring-beans-6.0.2.jar:/workspace/BOOT-INF/lib/micrometer-observation-1.10.2.jar:/workspace/BOOT-INF/lib/micrometer-commons-1.10.2.jar:/workspace/BOOT-INF/lib/spring-webmvc-6.0.2.jar:/workspace/BOOT-INF/lib/spring-aop-6.0.2.jar:/workspace/BOOT-INF/lib/spring-context-6.0.2.jar:/workspace/BOOT-INF/lib/spring-expression-6.0.2.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-3.0.0.jar com.example.boot3.MyApplication
[INFO] [creator] ================================================================================
[INFO] [creator] GraalVM Native Image: Generating '/layers/paketo-buildpacks_native-image/native-image/com.example.boot3.MyApplication' (static executable)...
[INFO] [creator] ================================================================================
[INFO] [creator] [1/7] Initializing... (39.3s # 0.16GB)
[INFO] [creator] Version info: 'GraalVM 22.3.0 Java 17 CE'
[INFO] [creator] Java version info: '17.0.5+8-LTS'
[INFO] [creator] C compiler: gcc (linux, x86_64, 7.5.0)
[INFO] [creator] Garbage collector: Serial GC
[INFO] [creator] 1 user-specific feature(s)
[INFO] [creator] - org.springframework.aot.nativex.feature.PreComputeFieldFeature
[INFO] [creator] The bundle named: org.apache.el.Messages, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.
[INFO] [creator]
[INFO] [creator] === Image generator watchdog detected no activity. This can be a sign of a deadlock during image building. Dumping all stack traces. Current time: Thu Nov 24 21:38:08 UTC 2022
I ran it multiple times and updated docker. I am using a macbook pro with m1 chip.
Docker is allowed to use 10 GB and 5 cores but is barely using 300mb RAM.
my pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
my main:
package com.example.boot3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
#SpringBootApplication
public class MyApplication {
#RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
EDIT:
I reinstalled docker, now the process went further but stuck again.
New logs:
[INFO] [creator] [1/7] Initializing... (39.7s # 0.16GB)
[INFO] [creator] Version info: 'GraalVM 22.3.0 Java 17 CE'
[INFO] [creator] Java version info: '17.0.5+8-LTS'
[INFO] [creator] C compiler: gcc (linux, x86_64, 7.5.0)
[INFO] [creator] Garbage collector: Serial GC
[INFO] [creator] 1 user-specific feature(s)
[INFO] [creator] - org.springframework.aot.nativex.feature.PreComputeFieldFeature
[INFO] [creator] The bundle named: org.apache.el.Messages, has not been found. If the bundle is part of a module, verify the bundle name is a fully qualified class name. Otherwise verify the bundle path is accessible in the classpath.
[INFO] [creator] Field org.springframework.core.NativeDetector#imageCode set to true at build time
[INFO] [creator] Field org.apache.commons.logging.LogAdapter#log4jSpiPresent set to true at build time
[INFO] [creator] Field org.apache.commons.logging.LogAdapter#log4jSlf4jProviderPresent set to true at build time
[INFO] [creator] Field org.apache.commons.logging.LogAdapter#slf4jSpiPresent set to true at build time
[INFO] [creator] Field org.apache.commons.logging.LogAdapter#slf4jApiPresent set to true at build time
[INFO] [creator] Field org.springframework.format.support.DefaultFormattingConversionService#jsr354Present set to false at build time
[INFO] [creator] Field org.springframework.core.KotlinDetector#kotlinPresent set to false at build time
[INFO] [creator] Field org.springframework.core.KotlinDetector#kotlinReflectPresent set to false at build time
[INFO] [creator] Field org.springframework.cglib.core.AbstractClassGenerator#imageCode set to true at build time
[INFO] [creator] [2/7] Performing analysis... [**********] (337.7s # 1.82GB)
[INFO] [creator] 10,223 (89.53%) of 11,418 classes reachable
[INFO] [creator] 16,614 (63.36%) of 26,220 fields reachable
[INFO] [creator] 48,428 (58.34%) of 83,017 methods reachable
[INFO] [creator] 466 classes, 138 fields, and 2,281 methods registered for reflection
[INFO] [creator] 63 classes, 68 fields, and 55 methods registered for JNI access
[INFO] [creator] 4 native libraries: dl, pthread, rt, z
[INFO] [creator] [3/7] Building universe... (26.5s # 2.12GB)
[INFO] [creator]
[INFO] [creator] Warning: Dynamic proxy method java.lang.reflect.Proxy.newProxyInstance invoked at org.springframework.core.annotation.SynthesizedMergedAnnotationInvocationHandler.createProxy(SynthesizedMergedAnnotationInvocationHandler.java:304)
[INFO] [creator] Warning: Dynamic proxy method java.lang.reflect.Proxy.newProxyInstance invoked at org.springframework.core.io.support.VfsPatternUtils.visit(VfsPatternUtils.java:51)
[INFO] [creator] Warning: Dynamic proxy method java.lang.reflect.Proxy.newProxyInstance invoked at org.springframework.beans.factory.support.AutowireUtils.resolveAutowiringValue(AutowireUtils.java:134)
[INFO] [creator] Warning: Aborting stand-alone image build due to dynamic proxy use without configuration.
[INFO] [creator] Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO] [creator] --------------------------------------------------------------------------------
[INFO] [creator] 12.8s (3.1% of total time) in 29 GCs | Peak RSS: 3.50GB | CPU load: 3.38
[INFO] [creator] ================================================================================
[INFO] [creator] Failed generating '/layers/paketo-buildpacks_native-image/native-image/com.example.boot3.MyApplication' after 6m 46s.
[INFO] [creator] Generating fallback image...
It says it failed to generating the image. Weird?
[1]: https://docs.spring.io/spring-boot/docs/3.0.0-SNAPSHOT/reference/html/native-image.html#native-image

create spring boot 2.7 'mvn spring-boot:build-image' with podman on macOS failed

I try to create an image with mvn spring-boot:build-image using podman but got
[INFO] --- spring-boot-maven-plugin:2.7.0:build-image (default-cli) # sample-spring-service ---
[INFO] Building image 'docker.io/library/sample-spring-service:1.0.0-SNAPSHOT'
[INFO]
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
[INFO] > Pulled builder image 'docker.io/paketobuildpacks/builder#sha256:94e65320ba1682bc68cbbf1d4f63693bb62cc06c7077bfa3e3bccac7fdc10628'
[INFO] > Pulling run image 'docker.io/paketobuildpacks/run:base-cnb' 100%
[INFO] > Pulled run image 'docker.io/paketobuildpacks/run#sha256:3e889016680c0e2ef1e8b1bfdad2d6d34966c860a53ccfcfb3e269d48ed65fed'
[INFO] > Executing lifecycle version v0.14.1
[INFO] > Using build cache volume 'pack-cache-744ddec35876.build'
[INFO]
[INFO] > Running creator
[INFO] [creator] ERROR: initializing analyzer: getting previous image: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied
podman info:
host:
arch: amd64
buildahVersion: 1.26.1
cgroupControllers:
...
version:
APIVersion: 4.1.0
Built: 1651853754
BuiltTime: Fri May 6 18:15:54 2022
GitCommit: ""
GoVersion: go1.18
Os: linux
OsArch: linux/amd64
Version: 4.1.0
I already tried a lot. Set permissions on socket, run podman with root. The same with docker is working well.
podman create alpine ls works fine.
In my pom.xml I tried:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<docker>
<!-- <host>unix:///Users/mike/.local/share/containers/podman/machine/podman-machine-default/podman.sock</host>
<host>unix:///run/user/1000/podman/podman.sock</host>
-->
<bindHostToBuilder>true</bindHostToBuilder>
</docker>
</configuration>
</plugin>
Any idea?
Update:
If I enable this line in pom.xml:
unix:///run/user/1000/podman/podman.sock
I get:
[INFO] --- spring-boot-maven-plugin:2.7.0:build-image (default-cli) # sample-spring-service ---
[INFO] Building image 'docker.io/library/sample-spring-service:1.0.0-SNAPSHOT'
[INFO]
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:base' 100%
For anyone who runs into a similar issue with spring boot build-image, for example when using remote docker hosts
From what I understand:
the pull is done using your docker parameters in pom.xml or environment variables like DOCKER_HOST
Once the pull has been completed, creator will start a new container and run the next commands in this newly container
The connection to docker in the new container might not work, as the DOCKER_HOST might need to be different for access to docker within a new container. Within the "creator" container, /var/run/docker.sock is automatically mounted from the host system.
If you enable bindHostToBuilder, it'll pass the DOCKER_HOST (or the parameter in pom.xml) to the new container, but that might not be the correct docker hostname that is accessible from within the new container.
For me the solution was to not use bindHostToBuilder, but ensure that /var/run/docker.sock exists on the host system so that it can be mapped within the "creator" container, even though the pull happens with a different DOCKER_HOST (a remote docker)

`#PreAuthorize` with spring-native triggers packaging error: `repeated interface: org.springframework.aop.SpringProxy`

I'm trying to build native images for spring-boot apps in a maven multi-module project.
As soon as I decorate a #Controller method with #PreAuthorize, native image generation fail with the message below.
Following spring-native samples, I tryed both with (as done in security-method-class-proxies) and without (as done in security-method) #AotProxyHint on application class, but this made no difference.
The error:
[INFO] [creator] Error: Error parsing dynamic proxy configuration in file:/workspace/META-INF/native-image/org.springframework.aot/spring-aot/proxy-config.json:
[INFO] [creator] java.lang.IllegalArgumentException: repeated interface: org.springframework.aop.SpringProxy
[INFO] [creator] Verify that the configuration matches the schema described in the -H:PrintFlags=+ output for option DynamicProxyConfigurationResources.
[INFO] [creator] Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO] [creator] Error: Image build request failed with exit status 1
[INFO] [creator] unable to invoke layer creator
[INFO] [creator] unable to contribute native-image layer
[INFO] [creator] error running build
[INFO] [creator] exit status 1
[INFO] [creator] ERROR: failed to build: exit status 1
Any clue why?
I figured out two things about this error:
as soon as #PreAuthorize targets a class member (not an interface), configuration must provide an #AotProxyHint(targetClass = ..., proxyFeatures = ProxyBits.IS_STATIC) for this class
there is bug on Windows about that declared in spring-native issues

Building a Spring Native application on my Docker Image

I am building my spring boot native application on an alpine (openjdk:13-alpine) docker image.
./mvnw spring-boot:build-image -DskipTests
When doing this I got an error :
[INFO] Building image 'docker.io/library/bff-distributor:0.0.1-SNAPSHOT'
[INFO]
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory
[INFO] Retrying request to {}->docker://localhost:2376
[INFO] > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' 100%
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:54 min
[INFO] Finished at: 2021-04-16T15:26:34Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image (default-cli) on project bff-distributor: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:build-image failed: Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible: com.sun.jna.LastErrorException: [2] No such file or directory -> [Help 1]
My gitlab.ci configuration
build:
image: openjdk:13-alpine
stage: build
script:
- chmod 755 ./mvnw
- ./mvnw spring-boot:build-image -DskipTests
For information : I need it to be running on a docker image as the building it's part of my gitlab ci/cd stage.
As the link provided Scott says, you should use Docker in Docker to do what you want.
So, replace the openjdk image by the docker image (https://hub.docker.com/_/docker) and activate the dind service.
As you need Java for the Maven execution, you can simply install jdk in the "before_script" section.
Here is my gitlab-ci script for the same kind of project :
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
image: docker:20.10.8-dind-alpine3.13
services:
- docker:20.10.8-dind
stage: build_push
before_script:
- apk add --update openjdk11
script:
- chmod 755 ./mvnw
- ./mvnw spring-boot:build-image

Resources