title: Multi-Branch Pipeline project with Jenkinsfile and Docker best practise
body: <p>I am new with Jenkins and Docker and have built a new multi-branch pipeline project to be independent from our build server configuration. My application includes a Jenkinsfile with several stages and uses two docker images: one is the official Mongo image from DockerHub, the other docker image is created by myself and includes Maven and Mercurial.</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM maven:3.3.9-jdk-8
  RUN apt-get update &amp;&amp; apt-get install -y -q mercurial
  </code></pre>
  
  <p>I use this to checkout my project in stage one and build it in stage two with maven.</p>
  
  <p>My Jenkinsfile looks as follows:</p>
  
  <pre><code>node {
  
      //...
  
      //CREATE A MONGO DOCKER IMAGE
      def dockerMongoImage = docker.image("mongo");
  
      // getting our maven container
      def maven = docker.build('my:docker', '../workspace')
  
      dockerMongoImage.withRun{ mongo -&gt;
          maven.inside("--link=${mongo.id}:mongo") {
              stage "checkout branch '${env.BRANCH_NAME}'"
  
                  def cloneUrl = createScmCloneUrl("https", scmUser, scmPassword, scmHref )
                  sh "hg clone ${cloneUrl} -r ${env.BRANCH_NAME} ${workingDir} --insecure"
  
              stage "build - running clean install"
                  runMvn(workingDir, mvnSettingsLocation, "clean install -U -V -DskipTests=true -X")
  
              // AND SO ON
  </code></pre>
  
  <p>The whole configuration is working fine but I'm not so happy with the checkout inside the container.
  My question is, is there any better solution than to do the checkout inside the container. This would prevent some problems with DNS I ran into. 
  Is there anybody who has some experience with that and can tell me what best practices are. I searched through google many many times but didn't get any nice solution for that.
  Thanks for any help.</p>