spring boot - Keep the docker container running while stopping and starting the process -
i have spring boot jar invoking on running docker container. running fine.
now, there other operations jar support. in order use operations, have invoke jar again (going inside container) passing in required parameters. problem operations kill running process, whatever change required starts app again. process gets killed docker container stops.
how keep container running during whole process?
i not discuss restarting automatically killed container, since not answer question (but depending on situation, may perhaps ask why solution not fit needs).
the container stopped when main process launched entrypoint, defined in image, killed in container. so, avoid stopping container, use entrypoint not stop when operations need restart java app. more over, entrypoint launch operations, process controler java application.
here dockerfile such example, can see entrypoint specific shell, not directly java container.
from [...] expose 443 [...] copy entrypoint.sh /usr/local/bin cmd chmod 755 /usr/local/bin/entrypoint.sh entrypoint ["/usr/local/bin/entrypoint.sh"]
now, write entrypoint.sh way:
#!/bin/bash [...] # launch spring boot jar in subprocess java -jar target/myproject-0.0.1-snapshot.jar > /dev/null 2>&1 & # or mvn spring-boot:run > /dev/null 2>&1 & # may detach java process shell job list, if needed disown %1 # wait infinitely "docker stop", should way stop container while sleep 1 echo waiting container terminated # if needed, launch app again (in case has been terminated , not relaunched automatically) if ! ps auxgww | grep -v grep | grep java java -jar target/myproject-0.0.1-snapshot.jar > /dev/null 2>&1 & # or mvn spring-boot:run > /dev/null 2>&1 & # may detach java process shell job list, if needed disown %1 fi done
Comments
Post a Comment