title: Running simple Java Gradle app in Docker
body: <p>I have a simple Java server app with a Gradle build. It works perfectly with <code>gradle run</code> on my host machine. However, I want to build this in a docker image and run as a docker container.</p>
  
  <p>I'm using docker-machine (version 0.13.0):</p>
  
  <pre><code>docker-machine create --driver virtualbox --virtualbox-memory 6000 default
  docker-machine start
  eval $(docker-machine env default)
  </code></pre>
  
  <p>I have the following <code>Dockerfile</code> image build script in <code>./serverapp/Dockerfile</code>:</p>
  
  <pre><code>FROM gradle:4.3-jdk-alpine
  ADD . /code
  WORKDIR /code
  CMD ["gradle", "--stacktrace", "run"]
  </code></pre>
  
  <p>I can build perfectly:</p>
  
  <pre><code>➜  docker build -t my-server-app .
  Sending build context to Docker daemon  310.3kB
  Step 1/4 : FROM gradle:4.3-jdk-alpine
   ---&gt; b803ec92baec
  Step 2/4 : ADD . /code
   ---&gt; Using cache
   ---&gt; f458b0be79dc
  Step 3/4 : WORKDIR /code
   ---&gt; Using cache
   ---&gt; d98d04eda627
  Step 4/4 : CMD ["gradle", "--stacktrace", "run"]
   ---&gt; Using cache
   ---&gt; 869262257870
  Successfully built 869262257870
  Successfully tagged my-server-app:latest
  </code></pre>
  
  <p>When I try to run this image:</p>
  
  <pre><code>➜  docker run --rm my-server-app
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
  &gt; Could not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.createCrossBuildFileHashCache().
  
  * Try:
  Run with --info or --debug option to get more log output.
  
  * Exception is:
  org.gradle.internal.service.ServiceCreationException: Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
      at org.gradle.internal.service.DefaultServiceRegistry$FactoryMethodService.invokeMethod(DefaultServiceRegistry.java:797)
  
    &lt;snip&gt;
      ... 60 more
  Caused by: org.gradle.api.UncheckedIOException: Failed to create parent directory '/code/.gradle/4.3' when creating directory '/code/.gradle/4.3/fileHashes'
      at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:271)
      at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:56)
  </code></pre>
  
  <p>Why would it have trouble creating that directory?</p>
  
  <p>This should be a very easy task, can anyone tell me how they get this simple scenario working?</p>
  
  <p>FYI, running current versions of everything. I'm using Gradle 4.3.1 on my host, and the official Gradle 4.3 base image from docker hub, I'm using the current version of JDK 8 on my host and the current version of docker, docker-machine, and docker-compose as well.</p>