I have two jar files(a.jar and b.jar). b.jar have dependency on a.jar. b.jar can run only after a.jar is up and running. I want to run them via single docker run command. My docker file is like this
# base image is java:8 (ubuntu)
FROM java:8
# add files to image
ADD a.jar .
ADD b.jar .
ADD start.sh .
# start on run
CMD ["bash", "start.sh"]
start.sh is like this ,
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar docker-spring-boot.jar &
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar docker-spring-boot-secondary.jar
When i am running docker image both jars are running simultaneously.
When my start.sh is like this,
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar docker-spring-boot.jar;
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar docker-spring-boot-secondary.jar;
Then only a.jar is running.
I took a help of this How to have two JARs start automatically on "docker run container"
Any help will be appreciated. thanks.
You need to write a script that checks if "a.jar is up and running" and insert it before the second jar call in the following way:
java -jar a.jar &
wait_till_a_jar_is_up_and_running &&
java -jar b.jar
Note: it is important that second time you use &&
but not &
.
None of us knows what "a.jar is up and running" as we don't know what a.jar does. You'll need to implement it yourself (most likely wait-for-it.sh will help you ).
For testing purposes you can try using sleep
command:
java -jar a.jar & sleep 10 && java -jar b.jar
Where sleep 10
just waits 10 seconds before running the second jar.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.