3

I'm trying to create docker image based on busybox with openjdk 11, for minimal java image

I used progrium/busybox as base image which contains glibc and installed zlib.so which was missing: opkg-install zlib-dev
Then I downloaded from https://jdk.java.net/11/ the compiled linux jdk.

Then when trying to run java -version it outputs the version but then crash. This is from the created log:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f6d7013d5c0, pid=47, tid=62
#
# JRE version: OpenJDK Runtime Environment (11.0.2+9) (build 11.0.2+9)
# Java VM: OpenJDK 64-Bit Server VM (11.0.2+9, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [libc.so.6+0x385c0]  __call_tls_dtors+0x10
#

full log here

I'd appreciate any advice or direction on how to solve this, thanks

matanper
  • 881
  • 8
  • 24

1 Answers1

2

The problem is that you have two versions of libc installed simultaneously in your base image - GNU libc and musl libc:

$ docker run -it progrium/busybox
/ #
/ # /lib64/libc.so.6
GNU C Library (Buildroot) stable release version 2.18, by Roland McGrath et al.
<...>
/ # 
/ # /lib64/libc.so
musl libc (x86_64)
<...>

The libc package, provided by opkg, is musl libc, and all binaries from opkg packages are built against it. This includes zlib, so, it turns out that musl libc is a transitive dependency for Java binary.

However, Java binary itself in your case is built against GNU libc, so you end up with two libc versions being loaded at the same time:

/ # LD_DEBUG=libs /opt/jdk/jdk-11.0.2/bin/java
<...>
572: calling init: /lib64/libc.so
<...>
572: calling init: /lib/libc.so.6

The result is pretty unpredictable, and in your case this is a segmentation fault.

If you want to download the JDK build from the official OpenJDK website, you have to use the Alpine Linux OpenJDK build, because Alpine also uses musl libc.

Unfortunately, this build is not present for OpenJDK 11, but you may check that Early Access OpenJDK 13 build for Alpine Linux works pretty well (but note that it is not a stable release build!).

Danila Kiver
  • 3,418
  • 1
  • 21
  • 31
  • Thanks for the explanation, I prefer currently JDK 11 because it is LTS. I tried `busybox:glibc` which compiled againt glibc but it is missing libz.so, and also `frolvlad/alpine-glibc` which contain glibc in seperate dir, but I couldn't manage to change the java shared libraries loading path – matanper Apr 17 '19 at 18:16
  • 2
    To be honest, I still use Java 8, which has Alpine version of OpenJDK image, `openjdk:8-jdk-alpine`, so I'm pretty surprised by the fact that there is _really no simple way_ to obtain a slim image of OpenJDK 11. Considering all the alternatives... If the stability really matters, I would not bother with lots of craftsmanship to save some megabytes and instead would use public Debian-based image. It is huge, but anyway it will be more stable than a custom hand-made slim build. – Danila Kiver Apr 18 '19 at 19:56