Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to use jar file inside docker container when downloaded

Context: I’m trying to use opentelemetry-javaagent in my spring project.

If I get the file using curl in my Dockerfile:

RUN curl https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.30.0/opentelemetry-javaagent.jar -o /tmp/opentelemetry-javaagent.jar && \
    chmod 540 /tmp/opentelemetry-javaagent.jar

When I run the docker image I get the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error opening zip file or JAR manifest missing : /tmp/opentelemetry-javaagent.jar
Error occurred during initialization of VM
agent library failed to init: instrument

However, if I manually download that exact file and add it:

ADD opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar
RUN chmod 540 /tmp/opentelemetry-javaagent.jar

It works fine. I’m probably missing something obvious but can’t put my finger on it. Does anyone know what I’m missing? Thanks in advance.

Here is the full Dockerfile:

FROM eclipse-temurin:17-jre

ARG RUN_JAVA_VERSION=1.3.8
ENV APP my-project
ENV JAVA_OPTIONS="-XshowSettings:vm"
ENV SPRING_PROFILES_ACTIVE=docker


ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,address=10200,server=y,suspend=n -javaagent:/tmp/opentelemetry-javaagent.jar -Dotel.service.name=format-adapter -Dotel.traces.exporter=zipkin

WORKDIR /app

RUN apt-get update -q \
    && apt-get install -y --no-install-recommends wget curl \
    && rm -Rf /var/lib/apt /var/cache/apt


RUN curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /app/run-java.sh && \
    chmod 540 /app/run-java.sh


#THIS DOESN'T WORK
RUN curl https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.30.0/opentelemetry-javaagent.jar -o /tmp/opentelemetry-javaagent.jar && \
    chmod 540 /tmp/opentelemetry-javaagent.jar

##THIS WORKS
#ADD opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar
#RUN chmod 540 /tmp/opentelemetry-javaagent.jar

ADD build/libs/${APP}-*.jar /app/${APP}.jar

HEALTHCHECK --interval=5m --timeout=3s \
  CMD curl -f http://localhost:${SERVER_PORT}/actuator/health || exit 1

ENTRYPOINT ["/app/run-java.sh"]

>Solution :

The given URL generates a redirect that curl does not follow unless you add the -L switch, so the curl command in your Dockerfile does not download anything.

As an alternative, wget follows redirects by default.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading