Reputation: 520
I have a simple Java code with three main classes. I want to build 3 different JARs out of it and then add those JARs to my Dockerfile and call each JAR in a different Docker image. How can I do it?
Upvotes: 2
Views: 8978
Reputation: 604
The Docker run
command accepts an optional COMMAND
argument. You can simply add 3 JARs to the Docker image and specify which to run via Docker command.
On the other hand, if you're willing to create multiple images of a single Dockerfile, docker currently supports multi-stage builds (that actually create multiple images) but does not allow you to tag every one of them.
Upvotes: 0
Reputation: 321
Adding bash script to execute multiple commands and blocks:
#start.sh
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar MyFirst.jar &
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar MySecond.jar
... etc
Change your Dockerfile:
# base image is java:8 (ubuntu)
FROM java:8
# add files to image
ADD first.jar .
ADD second.jar .
...
ADD start.sh .
# start on run
CMD ["bash", "start.sh"]
Upvotes: 3