title: Docker container can't write on host
body: <p>First of all, I couldn't find the answer here on SO (<a href="https://stackoverflow.com/questions/38760190/docker-container-not-able-to-write-on-host-machine">this is the closest post</a>).</p>
  
  <p>I have EC2 running Ubuntu. First I installed Jenkins, and then Docker.
  <strong>It's not "DonD".</strong></p>
  
  <p>My project has a Jenkinsfile, on that I'm running some docker commands.
  It's supposed to use a docker container like gradle, share a volume and build the project.</p>
  
  <p>The final .war will be on the host file system.</p>
  
  <p>The problem is: the gradle inside the container can't write on host's folder.</p>
  
  <p>Here's my Jenkinsfile (one of countless tries):</p>
  
  <pre><code>#!/usr/bin/groovy
  
  node {
      checkout scm
      stage 'Gradle'
  
      sh 'sudo docker run --rm -v "$PWD":/api -w /api gradle gradle clean build --stacktrace'
  }
  </code></pre>
  
  <p>Stacktrace important line:</p>
  
  <pre><code>Caused by: org.gradle.api.UncheckedIOException: Failed to create parent directory '/api/.gradle' when creating directory '/api/.gradle/4.3/fileHashes'
  </code></pre>