title: How to retain docker container after Jenkins pipeline build completed
body: <p>We've a Jenkins pipeline which runs on docker container and deploy app in tomcat but as soon as pipeline build completes, docker container is destroyed, hence we cannot access the installed app-</p>
  <p>Is there a way to retain docker container started through Jenkins pipeline after build finishes.</p>
  <p><strong>Pipeline sample code:</strong></p>
  <pre><code>pipeline {
      agent {
          docker {
              label '&lt;label-name&gt;'
              image '&lt;image-name&gt;'
              args '--cap-add SYS_ADMIN --cap-add DAC_READ_SEARCH -v $HOME/mavenrepo/module/repository:/usr/share/.m2/repository --user root --memory=9g'
          }
      }
      stages {
          //Few required stages here
  
          stage('Start Application server'){
              steps{
                  script{
                      FAILED_STAGE = env.STAGE_NAME
  
                      //startApplicationServer()
                      //checkServerStarted()
                  }
              }
          }
      }
  }
  </code></pre>
  <p>At the end of pipeline build, container destroy code is seen -</p>
  <pre><code>$ docker stop --time=1 b8445c83d7c9d08231c27f4f03f486d021fa1c0fa1d89c189231b069a2fbbf
  $ docker rm -f b8445c83d7c9d08231c27f4f03f486d021fa1c0fa1d89c189231b069a2fbbf
  [Pipeline] // withDockerContainer
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  Finished: SUCCESS
  </code></pre>