title: Jenkins Docker Pipeline override working directory
body: <p>I have noticed when using Jenkins with the Docker Pipeline plugin. When I create a Jenkins file to run commands in a docker container that it always creates a volume mapping of the Jenkins workspace directory mapped to the same path in the running container. It also creates a working directory with the same path.</p>
  
  <pre><code>docker run -t -d -u 127:134 -w /var/lib/jenkins/workspace/DockerTest 
  -v /var/lib/jenkins/workspace/DockerTest:/var/lib/jenkins/workspace/DockerTest:rw,z 
  -v /var/lib/jenkins/workspace/DockerTest@tmp:/var/lib/jenkins/workspace/DockerTest@tmp:rw,z 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  jekyll/jekyll:builder cat
  </code></pre>
  
  <p>I tried to override this by providing arguments in my Jenkinsfile for Docker like this:</p>
  
  <pre><code>pipeline {
    agent {
      docker {
        image 'jekyll/jekyll:builder'
        args '-v $HOME:/srv/jekyll -w /srv/jekyll'
      }
    }
    stages {
      stage('Test') {
        steps {
        sh 'cd /srv/jekyll &amp;&amp; ls -l'
        }
      }
    }
  }
  </code></pre>
  
  <p>It seems that this just prepends the options to the Docker command and the workdir and volume mapping gets overwritten by the default settings:</p>
  
  <pre><code>docker run -t -d -u 127:134 
  -v $HOME:/srv/jekyll 
  -w /srv/jekyll 
  -w /var/lib/jenkins/workspace/DockerTest 
  -v /var/lib/jenkins/workspace/DockerTest:/var/lib/jenkins/workspace/DockerTest:rw,z 
  -v /var/lib/jenkins/workspace/DockerTest@tmp:/var/lib/jenkins/workspace/DockerTest@tmp:rw,z 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  -e ******** 
  jekyll/jekyll:builder cat
  </code></pre>
  
  <p>Is there any way that I can override the volume mappings and working directory in any way?</p>