javaspringspring-bootgraalvmgraalvm-native-image

No such file or directory error on GraalVM


I had written so simple Spring Boot code. This code has just one controller page, one service page, one repository page and one domanin page. Following code my gradle file.

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.0'
    id 'io.spring.dependency-management' version '1.1.4'
    id 'org.graalvm.buildtools.native' version '0.9.28'
}

group = 'org.fsk'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '21'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

I want to run on graalvm this code.

./gradlew bootBuildImage --imageName=graalvmdemo:v001

While i want to generate a native image, i use to below terminal code.

When code generate image, i see image on docker name as graalvmdemo with v001 tag

But when i run this image on docker, i have an below error.

2023-12-20 01:45:09 qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

How can i fix this.?


Solution

  • This is a cross-architecture problem. Try adding FROM --platform=linux/amd64 to your Dockerfile. It will request the base image be linux/amd64.