shell - How to have two JARs start automatically on "docker run container" -
i want 2 seperate jar files executed automatically once docker container called via run command, when type docker run mycontainer
both called. far, have dockerfile looks this:
# base image java:8 (ubuntu) java:8 # add files image add first.jar . add second.jar . # start on run cmd ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "first.jar"] cmd ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "second.jar"]
this, however, starts second.jar.
now, both jars servers in loop, guess once 1 started blocks terminal. if run container using run -it mycontainer bash
, call them manually, too, first 1 outputs , can't start other one.
is there way open different terminals , switch between them have each jar run in own context? preferably in dockerfile.
i know next nothing ubuntu found xterm
command opens new terminal, won't work after calling jar. i'm looking instructions inside dockerfile example open new terminal, execute first.jar, alt-tab old terminal , execute second.jar there, or @ least achieve same.
thanks!
the second cmd instruction replaces first, need use single instruction both commands.
easy (not good) approach
you add bash script executes both commands , blocks on second one:
# start.sh /usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar first.jar & /usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar second.jar
then change dockerfile this:
# base image java:8 (ubuntu) java:8 # add files image add first.jar . add second.jar . add start.sh . # start on run cmd ["bash", "start.sh"]
when using docker stop
might not shut down properly, see: https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/
better approach
to solve this, use phusion: https://hub.docker.com/r/phusion/baseimage/
has init-system easier use e.g. supervisord.
here starting point: https://github.com/phusion/baseimage-docker#getting_started
instructions using phusion
sadly there not official openjdk-8-jdk available ubuntu 14.04 lts. try inofficial ppa, used in following explanation.
in case need bash scripts (which act "services"):
# start-first.sh (the file has start following line!): #!/bin/bash usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar /root/first.jar # start-second.sh #!/bin/bash usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar /root/second.jar
and dockerfile this:
# base image phusion phusion/baseimage:latest # use init service of phusion cmd ["/sbin/my_init"] # install unofficial openjdk-8 run add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get dist-upgrade -y && apt-get install -y openjdk-8-jdk add first.jar /root/first.jar add second.jar /root/second.jar # add first service run mkdir /etc/service/first add start-first.sh /etc/service/first/run run chmod +x /etc/service/first/run # add second service run mkdir /etc/service/second add start-second.sh /etc/service/second/run run chmod +x /etc/service/second/run # clean run apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
this should install 2 services run on startup , shut down when using docker stop
.
Comments
Post a Comment