Docker container can’t run jacoco agent with Java 12

I’m trying to run java docker image with my spring boot app. I want to use it for API testing and I want to collect code coverage as well. However I’m not able to make jacocoagent run inside docker container. Am I doing something wrong? Am I missing some setting somewhere? Regular bootJar runs smoothly when I don’t add agent. Moreover I’m able to execute the same command without problem outside of docker env. So it doesn’t seem to be a java bug.

Here is my docker-compose file:

version: '3.7'
services:
  bootJarTestApi:
    image: openjdk:12.0.1-jdk-oracle
    environment:
      - "JAVA_TOOL_OPTIONS=-javaagent:/jacoco-agent/jacocoagent.jar=destfile=/jacoco-report/apiDockerTest.exec,output=file"
    ports:
      - 2020:2020
      - 2021:2021
    volumes:
      - "./build/libs/bootJar.jar:/bootJar.jar"
      - "./build/libs/jacoco-agent/jacocoagent.jar:/jacoco-agent/jacocoagent.jar"
      - "./build/jacoco/:/jacoco-report/"
    entrypoint: ["java", "-jar",
#                 "-javaagent:/jacoco-agent/jacocoagent.jar=destfile=/jacoco-report/apiDockerTest.exec,output=file",
                 "-Dspring.profiles.active=dev",
                 "/bootJar.jar"]

When I try to run it, docker says:

bootJarTestApi_1  | Picked up JAVA_TOOL_OPTIONS: -javaagent:/jacoco-agent/jacocoagent.jar=destfile=/jacoco-report/apiDockerTest.exec,output=file
bootJarTestApi_1  | FATAL ERROR in native method: processing of -javaagent failed
bootJarTestApi_1  | mmap failed for CEN and END part of zip file
bootJarTestApi_1  | Unexpected error (103) returned by AddToSystemClassLoaderSearch
bootJarTestApi_1  | Unable to add /jacoco-agent/jacocoagent.jar to system class path - the system class loader does not define the appendToClassPathForInstrumentation method or the method failed
bootJarTestApi_1  | #
bootJarTestApi_1  | # A fatal error has been detected by the Java Runtime Environment:
bootJarTestApi_1  | #
bootJarTestApi_1  | #  SIGSEGV (0xb) at pc=0x00007f85d2728b07, pid=1, tid=7
bootJarTestApi_1  | #
bootJarTestApi_1  | # JRE version: OpenJDK Runtime Environment (12.0.1+12) (build 12.0.1+12)
bootJarTestApi_1  | # Java VM: OpenJDK 64-Bit Server VM (12.0.1+12, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
bootJarTestApi_1  | # Problematic frame:
bootJarTestApi_1  | # C  [libc.so.6+0x37b07]  abort+0x297
bootJarTestApi_1  | #
bootJarTestApi_1  | # Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e" (or dumping to //core.1)
bootJarTestApi_1  | #
bootJarTestApi_1  | # An error report file with more information is saved as:
bootJarTestApi_1  | # //hs_err_pid1.log
bootJarTestApi_1  | #
bootJarTestApi_1  | # If you would like to submit a bug report, please visit:
bootJarTestApi_1  | #   http://bugreport.java.com/bugreport/crash.jsp
bootJarTestApi_1  | #
bootJarTestApi_1  | 
bootJarTestApi_1  | [error occurred during error reporting (), id 0xb, SIGSEGV (0xb) at pc=0x00007f85d2728b07]

Source: StackOverflow