title: Building docker image - Gradle build daemon disappeared unexpectedly
body: <p>SO family, I've been working on a project using Docker, Gradle, and Kotlin.The issue is
  whenever I try to build a new docker image to deploy my latest changes, it gives an error</p>
  <blockquote>
  <p><strong>FAILURE: Build failed with an exception.</strong>
  What went wrong:
  <strong>Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)</strong></p>
  </blockquote>
  <p>I've tried to clear the memory multiple times by removing extra docker images and containers but couldn't succeed.
  <strong>The complete log file is attached.</strong></p>
  <pre><code>Step 1/19 : FROM xyz-image as build
   ---&gt; 1ed71d09935d
  Step 2/19 : RUN apk --no-cache --update add postgresql-client
   ---&gt; Using cache
   ---&gt; 8a7e3e5df31c
  Step 3/19 : ENV APP_HOME=/workspace
   ---&gt; Using cache
   ---&gt; d46fa561ccbf
  Step 4/19 : WORKDIR $APP_HOME
   ---&gt; Using cache
   ---&gt; 438c463befb9
  Step 5/19 : COPY . .
   ---&gt; 83e81d9f7ee7
  Step 6/19 : RUN chmod 777 ./gradlew &amp;&amp;  ./gradlew clean build --stacktrace test jacocoTestReport sonarqube
   ---&gt; Running in bc7a8bc75fed
  ./gradlew: line 1: Content#!/usr/bin/env: not found
  Downloading https://services.gradle.org/distributions/gradle-5.4.1-bin.zip
  ...................................................................................
  
  Welcome to Gradle 5.4.1!
  
  Here are the highlights of this release:
   - Run builds with JDK12
   - New API for Incremental Tasks
   - Updates to native projects, including Swift 5 support
  
  For more details see https://docs.gradle.org/5.4.1/release-notes.html
  
  Starting a Gradle Daemon (subsequent builds will be faster)
  &gt; Task :clean UP-TO-DATE
  &gt; Task :compileKotlin
  
  The message received from the daemon indicates that the daemon has disappeared.
  Build request sent: Build{id=e70a3593-58dd-4d13-9cc0-3064a72c8175, currentDir=/workspace}
  Attempting to read last messages from the daemon log...
  Daemon pid: 49
    log file: /root/.gradle/daemon/5.4.1/daemon-49.out.log
  ----- Last  20 lines from daemon log file - daemon-49.out.log -----
  05:57:15.389 [ERROR] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] Command execution: started DaemonCommandExecution[command = Build{id=e70a3593-58dd-4d13-9cc0-3064a72c8175, currentDir=/workspace}, connection = DefaultDaemonConnection: socket connection from /127.0.0.1:34029 to /127.0.0.1:47592] after 0.0 minutes of idle
  05:57:15.390 [INFO] [org.gradle.launcher.daemon.server.DaemonRegistryUpdater] Marking the daemon as busy, address: [b5d2ee0e-ade8-438a-a2a1-d0b724bd1ee9 port:34029, addresses:[/127.0.0.1]]
  05:57:15.390 [DEBUG] [org.gradle.launcher.daemon.registry.PersistentDaemonRegistry] Marking busy by address: [b5d2ee0e-ade8-438a-a2a1-d0b724bd1ee9 port:34029, addresses:[/127.0.0.1]]
  05:57:15.391 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
  05:57:15.391 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
  05:57:15.396 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
  05:57:15.398 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] resetting idle timer
  05:57:15.399 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] daemon is running. Sleeping until state changes.
  05:57:15.400 [INFO] [org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy] Daemon is about to start building Build{id=e70a3593-58dd-4d13-9cc0-3064a72c8175, currentDir=/workspace}. Dispatching build started information...
  05:57:15.401 [DEBUG] [org.gradle.launcher.daemon.server.SynchronizedDispatchConnection] thread 17: dispatching class org.gradle.launcher.daemon.protocol.BuildStarted
  05:57:15.403 [DEBUG] [org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment] Configuring env variables: {PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/jdk/bin, JAVA_JCE=standard, APP_HOME=/workspace, JAVA_HOME=/opt/jdk, OLDPWD=/workspace, GLIBC_VERSION=2.27-r0, LANG=C.UTF-8, JAVA_VERSION_MAJOR=8, HOSTNAME=bc7a8bc75fed, JAVA_VERSION_TOKEN=42970487e3af4f5aa5bca3f542482c60, GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc, JAVA_VERSION_MINOR=201, PWD=/workspace, JAVA_PACKAGE=jdk, JAVA_VERSION_BUILD=09, HOME=/root, SHLVL=2}
  05:57:15.406 [DEBUG] [org.gradle.launcher.daemon.server.SynchronizedDispatchConnection] thread 15: received class org.gradle.launcher.daemon.protocol.CloseInput
  05:57:15.407 [DEBUG] [org.gradle.launcher.daemon.server.DefaultDaemonConnection] thread 15: Received IO message from client: org.gradle.launcher.daemon.protocol.CloseInput@6181a140
  05:57:15.411 [DEBUG] [org.gradle.launcher.daemon.server.exec.LogToClient] About to start relaying all logs to the client via the connection.
  05:57:15.411 [INFO] [org.gradle.launcher.daemon.server.exec.LogToClient] The client will now receive all logging from the daemon (pid: 49). The daemon log file: /root/.gradle/daemon/5.4.1/daemon-49.out.log
  05:57:15.414 [INFO] [org.gradle.launcher.daemon.server.exec.LogAndCheckHealth] Starting build in new daemon [memory: 477.6 MB]
  05:57:15.415 [INFO] [org.gradle.launcher.daemon.server.exec.ForwardClientInput] Closing daemon's stdin at end of input.
  05:57:15.416 [INFO] [org.gradle.launcher.daemon.server.exec.ForwardClientInput] The daemon will no longer process any standard input.
  05:57:15.420 [DEBUG] [org.gradle.launcher.daemon.server.exec.ExecuteBuild] The daemon has started executing the build.
  05:57:15.420 [DEBUG] [org.gradle.launcher.daemon.server.exec.ExecuteBuild] Executing build with daemon context: DefaultDaemonContext[uid=ff30b05d-4eb7-4a0f-b3e6-b9043b11d71f,javaHome=/opt/jdk1.8.0_201,daemonRegistryDir=/root/.gradle/daemon,pid=49,idleTimeout=10800000,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country,-Duser.language=en,-Duser.variant]
  ----- End of the daemon log -----
  
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
  
  * Try:
  Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  
  * Exception is:
  org.gradle.launcher.daemon.client.DaemonDisappearedException: Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
          at org.gradle.launcher.daemon.client.DaemonClient.handleDaemonDisappearance(DaemonClient.java:241)
          at org.gradle.launcher.daemon.client.DaemonClient.monitorBuild(DaemonClient.java:217)
          at org.gradle.launcher.daemon.client.DaemonClient.executeBuild(DaemonClient.java:179)
          at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:142)
          at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:94)
          at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:55)
          at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:208)
          at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:394)
          at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:367)
          at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:37)
          at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:23)
          at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:360)
          at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:292)
          at org.gradle.launcher.Main.doAction(Main.java:36)
          at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
          at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
          at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:31)
          at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:108)
          at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:62)
  
  
  * Get more help at https://help.gradle.org
  The command '/bin/sh -c chmod 777 ./gradlew &amp;&amp;  ./gradlew clean build --stacktrace test jacocoTestReport sonarqube' returned a non-zero code: 1
  </code></pre>
  <p><em><strong>Thanks for your help in advance.</strong></em></p>