Skip to content

Cannot run using openjdk:8-jdk-alpine image #5

@eljasala

Description

@eljasala

It seems like this currently cannot be run on Alpine. Most probable reason I have found so far is that Alpine uses musl instead of glibc.

$ cat Dockerfile 
FROM openjdk:8-jdk-alpine
RUN mkdir -p /opt/cprof && wget -q -O- https://storage.googleapis.com/cloud-profiler/java/latest/profiler_java_agent.tar.gz | tar xzv -C /opt/cprof
WORKDIR /app
ADD Main.java .
RUN javac Main.java; jar cfve file.jar Main Main.class
RUN apk add --no-cache libc6-compat
CMD ["java", "-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=javatest,-cprof_service_version=1.0.0", "-jar", "file.jar"]

$ cat Main.java 
class Main {
    public static void main(String[] args) {
        while (true) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {
                break;
            }
            System.out.println("Hello World!");
        }
    }
}

$ docker build -t foo . && docker run --rm foo
Sending build context to Docker daemon  73.32MB
Step 1/7 : FROM openjdk:8-jdk-alpine
 ---> 54ae553cb104
Step 2/7 : RUN mkdir -p /opt/cprof && wget -q -O- https://storage.googleapis.com/cloud-profiler/java/latest/profiler_java_agent.tar.gz | tar xzv -C /opt/cprof
 ---> Using cache
 ---> 1e272a02dc1d
Step 3/7 : WORKDIR /app
 ---> Using cache
 ---> eabb8027399c
Step 4/7 : ADD Main.java .
 ---> Using cache
 ---> d4d7d0d51f9c
Step 5/7 : RUN javac Main.java; jar cfve file.jar Main Main.class
 ---> Using cache
 ---> 8d9bb4741cfd
Step 6/7 : RUN apk add --no-cache libc6-compat
 ---> Using cache
 ---> c9cc1fd8e889
Step 7/7 : CMD ["java", "-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=javatest,-cprof_service_version=1.0.0", "-jar", "file.jar"]
 ---> Using cache
 ---> 180f3ac16704
Successfully built 180f3ac16704
Successfully tagged foo:latest
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000000076a96, pid=1, tid=0x00007ff076e81ae8
#
# JRE version: OpenJDK Runtime Environment (8.0_171-b11) (build 1.8.0_171-b11)
# Java VM: OpenJDK 64-Bit Server VM (25.171-b11 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 3.8.0
# Distribution: Custom build (Wed Jun 13 18:28:11 UTC 2018)
# Problematic frame:
# C  0x0000000000076a96
#
# Core dump written. Default location: /app/core or core.1
#
# An error report file with more information is saved as:
# /app/hs_err_pid1.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
#   http://icedtea.classpath.org/bugzilla
#

I tried re-compiling the library to link against musl. In Dockerfile I had to make following changes:

  • Replace apt-get install ... with apk add build-base git autoconf automake libtool openssl-dev python zlib zlib-dev
  • Change ... && ldconfig && ... to ... && ldconfig / && ....

That was enough to get the build environment up, but unfortunately the build itself fails due to some musl & glibc incompatibilities.

src/cloud_env.cc: In function 'const char* cloud::profiler::{anonymous}::Getenv(const string&)':
src/cloud_env.cc:73:37: error: '__secure_getenv' was not declared in this scope
   return __secure_getenv(var.c_str());
                                     ^
src/threads.cc: In function 'void* cloud::profiler::{anonymous}::CreateTimer(pid_t)':
src/threads.cc:31:23: error: 'SIGEV_THREAD_ID' was not declared in this scope
   sevp.sigev_notify = SIGEV_THREAD_ID;
                       ^~~~~~~~~~~~~~~
src/threads.cc:32:8: error: 'struct sigevent' has no member named '_sigev_un'; did you mean 'sigevent'?
   sevp._sigev_un._tid = tid;
        ^~~~~~~~~

__secure_getenv should be fairly easy to fix with fallback to getenv if needed, but I'm not sure about the thread signaling stuff.

Metadata

Metadata

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions