英文:
Custom runtime image for Alpine
问题
以下是翻译好的内容:
我正在尝试使用 The Badass Runtime Plugin 创建一个自定义运行时镜像,然后在 Alpine 上执行它。但是它失败并显示以下错误消息:
jibcmd_1 | /bin/sh: exec: line 1: ./bin/jibcmd: not found
如果我执行类似于 docker run -it jibcmd_jibcmd ls -l /app/bin/jibcmd
的操作,毫无疑问该文件是存在的。
如果我将父镜像从 Alpine 更改为 Debian,一切都能正常工作。但我想使用 Alpine。
下面是我的 build.gradle 文件:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'application'
id "com.github.johnrengelman.shadow" version "5.2.0"
id "org.beryx.runtime" version "1.8.0"
}
// ...(其余部分未翻译)
下面是我的 Dockerfile:
FROM openjdk:14-jdk-buster AS builder
# ...(其余部分未翻译)
FROM alpine
# ...(其余部分未翻译)
关于如何在 Alpine 上运行这个问题,有什么建议吗?
更新:
$ docker run -it jibcmd_jibcmd sh
/app # ldd /app/bin/jibcmd
/lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /app/bin/jibcmd)
/app # ls -l /lib64/ld-linux-x86-64.so.2
ls: /lib64/ld-linux-x86-64.so.2: No such file or directory
/app # apk add libc6-compat
# ...(其余部分未翻译)
/app # ls -l /lib64/ld-linux-x86-64.so.2
lrwxrwxrwx 1 root root 26 Apr 6 13:05 /lib64/ld-linux-x86-64.so.2 -> /lib/libc.musl-x86_64.so.1
/app # ldd /app/bin/jibcmd
/lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /app/bin/jibcmd)
ldd 仍然显示 ld-linux-x86-64.so.2 缺失...
<details>
<summary>英文:</summary>
I'm trying to create a custom runtime image using the [The Badass Runtime Plugin][1] and then execute it on Alpine. But it fails with the following error message.
jibcmd_1 | /bin/sh: exec: line 1: ./bin/jibcmd: not found
If I do something like `docker run -it jibcmd_jibcmd ls -l /app/bin/jibcmd` there's no doubt that the file is there.
If I change my parent image from Alpine to Debian everything works. But I'd like to use Alpine.
Below is my build.gradle file
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'application'
id "com.github.johnrengelman.shadow" version "5.2.0"
id "org.beryx.runtime" version "1.8.0"
}
group 'org.example'
version '1.0.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "com.github.ajalt:clikt:2.3.0"
implementation "com.google.cloud.tools:jib-core:0.12.0"
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438'
implementation 'com.sun.xml.ws:jaxws-ri:2.3.2'
}
runtime {
modules = ['java.logging', 'java.desktop', 'java.compiler', 'java.xml']
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Below is my Dockerfile
FROM openjdk:14-jdk-buster AS builder
WORKDIR /src
COPY *.gradle *.properties gradlew ./
COPY gradle gradle
RUN ./gradlew --version
COPY . .
RUN ./gradlew jpackageImage
FROM alpine
#FROM debian
WORKDIR /app
COPY --from=builder /src/build/jpackage/jibcmd .
CMD exec ./bin/jibcmd
Any suggestions regarding how to get this to run on Alpine?
*Update*
$ docker run -it jibcmd_jibcmd sh
/app # ldd /app/bin/jibcmd
/lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /app/bin/jibcmd)
/app # ls -l /lib64/ld-linux-x86-64.so.2
ls: /lib64/ld-linux-x86-64.so.2: No such file or directory
/app # apk add libc6-compat
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/1) Installing libc6-compat (1.1.24-r2)
OK: 6 MiB in 15 packages
/app # ls -l /lib64/ld-linux-x86-64.so.2
lrwxrwxrwx 1 root root 26 Apr 6 13:05 /lib64/ld-linux-x86-64.so.2 -> /lib/libc.musl-x86_64.so.1
/app # ldd /app/bin/jibcmd
/lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /app/bin/jibcmd)
ldd still claim that ld-linux-x86-64.so.2 is missing...
[1]: https://badass-runtime-plugin.beryx.org/releases/latest/
</details>
# 答案1
**得分**: 0
这可以通过使用带有Glibc的Alpine镜像来解决。
<details>
<summary>英文:</summary>
This can be solved by using an Alpine image with Glibc
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论