Search code examples
javadockergradlebuildgretty

Running Gretty project with Gradle Docker container


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:

  1. Install Docker.
  2. Clone https://github.com/haba713/hello_gretty.
  3. cd hello_gretty
  4. Install Gradle wrapper: docker run --rm -u gradle -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle wrapper
  5. Run the task tomcatRun: ./gradlew tomcatRun
  6. Browse http://localhost:8080/hello_gretty.
  7. Terminate the task by pressing enter in terminal.
  8. Run task tomcatRun with Gradle Docker image: docker run --rm -u gradle -p 8080:8080 -v "$PWD":/home/gradle/project -w /home/gradle/project gradle gradle tomcatRun
  9. The task tomcatRun is 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.


Solution

  • Adding -t or --tty to docker command keeps Tomcat running. Also add -i or --interactive if 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 tomcatRun

    Thank you David Maze for helping.