问题
Dockerfile works correctly for tomcat. After tomcat starts, I have to trigger ant scripts. catalina.sh is started from a separate run.sh file. So, Dockerfile has CMD ["/tmp/run.sh"]
The run.sh file has below lines:
- catalina.sh run
- antscript
Tomcat starts but ant scripts are not called. I also tried other possibilities like:
- catalina.sh run && antscripts
tomcat starts but antscripts are not triggered
Is there a way that I can call the ant scripts automatically after tomcat starts? I dont want to run the scripts afterwards by using docker exec.
回答1:
One of the ways, I can think of achieving the functionality is
- Starting antscripts with nohup command before catalina.sh,
- and adding a delay in antscript (use a wrapper shell script with sleep command).
The delay can be simple time based wait, or could just watch tomcat logs till server startup is complete to start execution.
回答2:
You can write you commands next way:
catalina.sh run & (sleep 20 && antscripts)
It will call antscripts in 20 seconds after catalina execution start. You can change time for estimated time of tomcat start.
Also you can wait for open some tcp port:
catalina.sh run & ((while ! echo exit | nc localhost 8080; do sleep 10; done) && antscripts)
来源:https://stackoverflow.com/questions/37437658/docker-execute-ant-script-after-tomcat-starts