Is it possible to run Gretty projects in Docker Gradle container?
Normally the Gretty task tomcatRun starts Tomcat app server and you can browse the app at http://localhost:8080/app-name. With Docker Gradle image the task is successfully started but the container is terminated immediately after that.
Steps for reproducing the issue:
- Install Docker.
- Clone https://github.com/haba713/hello_gretty.
cd hello_gretty- Install Gradle wrapper:
docker run --rm -u gradle -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle wrapper - Run the task
tomcatRun:./gradlew tomcatRun - Browse http://localhost:8080/hello_gretty.
- Terminate the task by pressing enter in terminal.
- Run task
tomcatRunwith Gradle Docker image:docker run --rm -u gradle -p 8080:8080 -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle tomcatRun - The task
tomcatRunis started (takes some time) but for some reason the container terminates immediately after that. Maybe the task was completed without pressing any key.
I also created a Docker issue about the problem.
Adding
-tor--ttytodockercommand keeps Tomcat running. Also add-ior--interactiveif you want to stop Tomcat with "any key" as Gretty says: "Press any key to stop the server."docker run --rm -u gradle -it -p 8080:8080 -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle tomcatRunThank you David Maze for helping.