# Sharing docker workspaces between stages

**URL:** <https://community.jenkins.io/t/sharing-docker-workspaces-between-stages/33642>\
**Category:** Ask a question\
**Tags:** docker\
**Created:** [July 8, 2025, 5:57am UTC](https://community.jenkins.io/t/sharing-docker-workspaces-between-stages/33642 "2025-07-08T05:57:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnbond](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/gnbond/32/14559_2.png) [@gnbond](https://community.jenkins.io/u/gnbond)\
**Post date:** [July 8, 2025, 5:57am UTC](https://community.jenkins.io/t/sharing-docker-workspaces-between-stages/33642/1 "2025-07-08T05:57:16Z")

</div>

Jenkins setup: 2.426.3 (yes its old)  
Java 11.0.22 (also old) on a container on rl8 linux

We have a MultiBranch Declarative pipeline using docker (actually, podman) containers. For one task, we need to build the product using one image, then run the tests using another image (different OS as the build OS doesn’t support the test tools), but the tests obviously should run in the same workspace where the built binaries are.

This _seems_ to be what reuseNode is for, but it doesn’t seem to be working - the test stage is usually run on a different docker host

```auto
agent {label "podman"}
stages {
stage("build") {
agent { docker { image "image1" } }
steps { ... }
}
stage("test") {
agent { 
  docker { image "image2"
  reuseNode true }
}
steps{...}
}
}

```

What am I missing here? Are there alternatives I could use to share workspace between the stages?  
I could possibly use stash/unstash but the list of stashed files might be large and somewhat dynamic.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [July 8, 2025, 9:56am UTC](https://community.jenkins.io/t/sharing-docker-workspaces-between-stages/33642/2 "2025-07-08T09:56:53Z")

</div>

As far as I understand it, you are correct that `reuseNode` true is intended to run the container on the same Jenkins node (host), but it does not guarantee the same workspace directory across different containers. Each `docker` block by default creates a new container, and unless you explicitly mount the workspace, the files from the build stage will not be available in the test stage.

Could we mount explicitly the workspace into both containers?

```auto
pipeline {
  agent { label 'podman' }
  stages {
    stage('build') {
      agent {
        docker {
          image 'image1'
          args "-v ${env.WORKSPACE}:${env.WORKSPACE}"
        }
      }
      steps {
        dir("${env.WORKSPACE}") {
          // build steps
        }
      }
    }
    stage('test') {
      agent {
        docker {
          image 'image2'
          reuseNode true
          args "-v ${env.WORKSPACE}:${env.WORKSPACE}"
        }
      }
      steps {
        dir("${env.WORKSPACE}") {
          // test steps
        }
      }
    }
  }
}

```
