[Edit: I’m running Docker Desktop 4.34.3 (170107)
on Windows 11 Pro 23H2 (10.0.22631.4317)
using WSL2
version 2.3.24.0
kernel 5.15.153.1-2]
[Edit2: I stuck a read -pdone
at the end of the start-tomcat.sh script. The app runs if I exec the script from outside. When I press Enter, the script exits normally, and Tomcat instantly dies. It does not shut down cleanly, the process simply ceases to exist as if someone did a kill -9
on it. I even tried ./startup.sh &
in the script. The parent PID becomes 1 as you’d expect, but when the parent script exits, something hunts Tomcat down and kills it.
It’s looking like you are not allowed to create a process and expect it to live beyond the docker compose exec
command. If you try, docker will hunt it down and nuke it from orbit.]
[Last edit, I think: I duct-taped it. My entrypoint.sh is a simple while true loop with a long sleep in there. It traps SIGTERM and cleanly shuts down Tomcat and exits.
I added a trap for SIGUSR1 which starts Tomcat up, and replaced the start-tomcat.sh contents with a simple kill -SIGUSR1 1
That starts Tomcat and it survives. So, now I can make my little powershell gui with buttons for starting and stopping Tomcat, pulling in war files, running db change scripts, etc.]
I have a weird issue. I created a Tomcat image for dev work on a web app.
(Before you say “you didn’t use the official Tomcat image…” – The app is running on Tomcat 8.5.100, and Java 8. I haven’t found an official image for that version. Yes, I am aware that 8.5 is EOL’d. Yes, we have set of projects on the books to upgrade the app to Java 11 and Tomcat 9 initially, and beyond, to Java 21+ and Spring Boot and Tomcat 10+. As Gowron liked to say, “But not today.”)
I put a very simple script in /usr/local/bin/start-tomcat.sh:
#!/bash/bin
cd /opt/tomcat/tomcat/bin
./catalina.sh start
(I do have chmod +x /usr/local/bin/*
in the Dockerfile)
If I go into bash with docker compose exec blah-tomcat bash
and run the script, Tomcat starts up fine, and the app runs.
If I try to run the script from outside with docker compose exec blah-tomcat start-tomcat.sh
the script runs, catalina.sh fires off its regular output of env variables, says “Tomcat started”.
Tomcat does not start. The catalina.out file is created but never written to. The length is 0. ps -ef
shows that the server is not running.
I have also tried docker compose exec blah-tomcat bash -c "start-tomcat.sh"
with the same non-results.
I have also tried docker compose exec blah-tomcat bash -c "cd /opt/tomcat/tomcat/bin && ./catalina.sh start"
with the same non-results.
If I change the start-tomcat.sh script to say ./catalina.sh run
it fires up the server and the app runs. But that means it is on stdout, no output to catalina.out. Not useful for debugging, as I cannot search for stuff in a file that doesn’t exist.
This is a dev environment. I want to be able to shut Tomcat down, pull in fresh war files, start Tomcat up, shut Tomcat down, mess with the db, start Tomcat up, etc.
Right now, that requires I open up a bash terminal and run the commands from within bash in the container. Sure, a minor inconvenience, but a big mystery. If this doesn’t work, what else will fail?
Does anyone have any hints on how to debug this?