I have to build single docker image for two independent programs, one is in java and one in c++. Now i have written dependencies in my dockerfile for c++ program and its working fine but when i checked for java , in all examples it was said to use base image of java (FROM openjdk:8-jre-alpine) but my problem is that i have to build image from a certain customised image only. I'm using ubuntu and i have run my simple java program by installing openjdk but i don't know how can i add dependencies for java correctly and run it in docker container along with c++.

I tried adding RUN apt-get install -y default-jdk but it returns non-zero code . I also tried RUN apt-get install oracle-java8-installer but it didn't worked either. Following is my Dockerfile.

FROM csimage/abcserver

RUN apt-get update -y 
RUN apt-get install -y g++ 
RUN apt-get install -y make
RUN apt-get install -y build-essential
RUN apt-get install -y default-jdk

#C++ program
ADD ./cppProgram /cppProgram

#java program
ADD ./javaProgram /javaProgram

WORKDIR /cppProgram
WORKDIR /javaProgram

COPY abcserver.json /etc/
RUN make 
  • "but it returns non-zero code" - can u watch logs: >> docker history image_name >> docker logs container_id ?
    – TheDESTROS
    May 30 '19 at 13:04

You can watch the error log:

docker history image_name
docker logs container_id

And you will find out why your container does not start. It’s hard to give you some other advice without having data from the container log. Perhaps these packages are not found in the repository.

Some tips:

If you have 2 independent applications, then you need a separate container for each of them. This is of course not necessary, but it is correct from an engineering point of view. Unite is not recommended (Perhaps of course in your case it is not applicable.)

Each RUN adds a new "layer", so I advise you to use "\":

RUN apt-get update -y && \
apt-get install -y g++ && \
apt-get install -y make && \
apt-get install -y build-essential && \
apt-get install -y default-jdk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.