Home » Java » java – "Activemq not found" error after running custom Docker image-Exceptionshub

java – "Activemq not found" error after running custom Docker image-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

We have a legacy application that I am trying to dockerize. The jar of the application has both the application and an activemq bundled together. (We cannot change the way it is built). And has certain installation steps. I created the following initial Dockerfile for this however I am facing an issue (mentioned after the Dockerfile) when I run the image.

The Dockerfile looks like this :

FROM registry:4000/openjdk:8-jre-alpine

RUN addgroup -S appuser && adduser -S -G appuser appuser

ADD ./fe.jar /home/appuser

RUN chmod +x /home/appuser/fe.jar \
&& chown appuser:appuser /home/appuser/fe.jar

USER appuser

RUN ["java", "-jar", "/home/appuser/fe.jar", "-i"]

WORKDIR /home/appuser/fe/activemq/bin

CMD ["/bin/sh", "-c", "activemq"]

The RUN command extracts the application and the activemq at the location into folder called fe.

The WORKDIR seems to be setting the working directly to activemq/bin. I confirmed this by using sh script which triggers when the image is run. In the sh script I trigger an ls and pwd command to see the contents and the location.

However when I run the image which triggers the CMD command I get the error that :

/bin/sh: activemq: not found

What can be the possible issue here?

How to&Answers:

If activemq is an executable in your bin directory (and not in PATH) then you need to edit your CMD:

CMD ["/bin/sh", "-c", "./activemq"]

Also make sure that your script is executable.

Answer:

Found the problem. The activemq script starts with #!/bin/bash and I am trying to run it using sh. I need to first install bash in the image and then run the activemq script using one.
I got the hint from this answer : docker alpine /bin/sh script.sh not found
Now it moved ahead however the container dies after running immediately. Not sure what the issue is. Doesn’t even give any error.