Running multile microservices with single parameterized image

I got 14 microservices, each microservice runs with same JAVA parameter but port expose is different and also jar names are different, i want to run all jars with one single base image, is there any way to achive that ? If Yes, how ? Since there are 14 images which is of 700M each, need to find optimal solution. can anybody suggest ?

Provided below sample docker file

FROM java:8
VOLUME /tmp
ADD sampleserver1.jar app.jar
RUN bash -c ‘touch /app.jar’
EXPOSE 8080
ENTRYPOINT [“java”,"-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

FROM java:8
VOLUME /tmp
ADD sampleserver2.jar app.jar
RUN bash -c ‘touch /app.jar’
EXPOSE 8082
ENTRYPOINT [“java”,"-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

One thing you can do, if all of the services are very similar, is to write a base Dockerfile with the common bits and build an image out of that

FROM java:8
EXPOSE 8080
CMD ["java", "-Djava.security.egd=file:/dev/urandom", "-jar", "/app.jar"]

and then build your individual service images on top of that

FROM my-java-base
COPY sampleserver1.jar /app.jar

That might be more interesting if there was more in the base image setup (adding custom SSL certificates; standard $JAVA_OPTS; …)

Sure, you could design something where you picked the jar to run via an environment variable or command-line argument. That shouldn’t be complicated, but it’s more code than fits in the post.

If you’re building and running the images locally, they’ll share the same java:8 base container, so you only pay that space overhead once. (I don’t know how true this is in a Swarm/Kubernetes/Nomad/… multi-host world.)

You also might switch to a “jre” or even “headless” variant of the openjdk image, especially if you’re building your jar file outside Docker, to not include a bunch of development tools you’re not using in your running image. (FROM openjdk:8-jre, for instance.)

Thanks, will implement and come back.