自定义用于 Alpine 的运行时镜像

huangapple go评论103阅读模式
英文:

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&#39;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&#39;s no doubt that the file is there.

If I change my parent image from Alpine to Debian everything works. But I&#39;d like to use Alpine.

Below is my build.gradle file

    plugins {
        id &#39;java&#39;
        id &#39;org.jetbrains.kotlin.jvm&#39; version &#39;1.3.61&#39;
        id &#39;application&#39;
        id &quot;com.github.johnrengelman.shadow&quot; version &quot;5.2.0&quot;
        id &quot;org.beryx.runtime&quot; version &quot;1.8.0&quot;
    }
    
    group &#39;org.example&#39;
    version &#39;1.0.0&#39;
    
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk8&quot;
        implementation &quot;com.github.ajalt:clikt:2.3.0&quot;
        implementation &quot;com.google.cloud.tools:jib-core:0.12.0&quot;
        testCompile group: &#39;junit&#39;, name: &#39;junit&#39;, version: &#39;4.12&#39;
    
        implementation &#39;org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438&#39;
        implementation &#39;com.sun.xml.ws:jaxws-ri:2.3.2&#39;
    }
    
    runtime {
        modules = [&#39;java.logging&#39;, &#39;java.desktop&#39;, &#39;java.compiler&#39;, &#39;java.xml&#39;]
    }
    
    compileKotlin {
        kotlinOptions.jvmTarget = &quot;1.8&quot;
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = &quot;1.8&quot;
    }

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 =&gt; /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
    	libm.so.6 =&gt; /lib64/ld-linux-x86-64.so.2 (0x7f0f4ba6a000)
    	libc.so.6 =&gt; /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 -&gt; /lib/libc.musl-x86_64.so.1
    /app # ldd /app/bin/jibcmd
    	/lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
    	libdl.so.2 =&gt; /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
    	libm.so.6 =&gt; /lib64/ld-linux-x86-64.so.2 (0x7f62a8afa000)
    	libc.so.6 =&gt; /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>



huangapple
  • 本文由 发表于 2020年4月6日 14:37:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/61054217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定