0

I am trying to run java with docker image in gitlab.

Here is my docker file.

  FROM java:latest
  FROM perl
  COPY . /
  ENTRYPOINT ["/usr/bin/perl", "/myapp_entrypoint.pl"]

I was able to build docker image successfully and run perl commands but java commands are not working.

My application is a linux application and I am running 'java -version'. I am not getting any output completely blank output for version command.

What would be the issue? Do I need to add anything related linux as I am running 'java -version' as linux command?

1 Answer 1

1

You don't specify what OS you're running in your container, but the main issue is that you're blowing away your Java layer with another FROM directive.

From the documentation, emphasis mine:

Each FROM instruction clears any state created by previous instructions.

So I'd espouse a solution in which I install Perl (if I really needed to) after having my base Java image.

However, if you use the base OpenJDK images, Perl comes preinstalled, so that will simplify your Dockerfile significantly.

FROM openjdk:latest
COPY . /
ENTRYPOINT ["/usr/bin/perl", "/myapp_entrypoint.pl"]
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much. It is working now. One doubt , If FROM removing previous state then what if I have more than 1 dependancies and I want to utilize all of them? Like in my problem I need both perl and java .So, what if openjdk image is not having in-built perl?
@Rekha: Install it like you would on any modern OS. Specify the command line argument (yum, apt, etc) and perform an installation of what you need in your Dockerfile.
An example would be more helpful to understand this. Could you provide an example ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.