dockergradledockerfilegradle-daemon

How to avoid start of Gradle daemon inside Dockerfile


I have the following Dockerfile:

FROM gradle:6.3-jdk8 as builder
WORKDIR /
COPY . /
RUN gradle shadow --no-daemon
EXPOSE 9999
CMD ["java", "-jar", "search-all.jar"]

I want to avoid Gradle daemon starting every time I build the image. Is there any possibility or a workaround to achieve this? I mentioned the --no-daemon but it is still started.


Solution

  • This question has already an extensive answer on the Gralde forums: Using –no-daemon, but still see a process called “Gradle Worker Daemon 1”.

    In short: The Gradle daemon process is the one executing the build and started always no matter on what has been specified on the command line. If --no-daemon is specified, the process is terminated after build completion.

    Original answer from the Gradle forums:

    My question is why is the daemon being created when we specify --no-daemon?

    The process run by Gradle to execute a build is the same whether or not you enable or disable the daemon. The behavior of the process after a build completes is the difference.

    With the daemon enabled, the process will continue running in the background and can reused for a subsequent build. With the daemon disabled, the process is terminated at the end of the build. Even with the daemon disabled, you will still see a process labeled as a daemon. It doesn’t mean it will continue running in the background like a daemon.