jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-54681] dir('path') is broken when used within "docker.image().inside{}"

Open
#591 1 comment 0 reactions 0 assignees View on GitHub
component:docker-workflow-plugin imported-jira-issue priority:blocker resolution:unresolved
Dominant language
Java
Stars
527
Forks
422
Avg merge
10m
Merged PRs (30d)
1

Description

It seems that when 'dir' is used within a docker container, it is expected that the directory exists on the host and not within the docker container. The following minimal Jenkinsfile showcases this issue:

 

node('docker') {

stage('Build within docker') {
// path to the workspace on the local machine and wthin the docker image
workspace = env.WORKSPACE
workspaceDocker = '/workspace'

image = docker.image("ubuntu:18.04")
image.pull()

image.inside("-v ${workspace}:${workspaceDocker}") {
sh 'pwd'

sh """#!/bin/sh
cd ${workspaceDocker}
pwd
"""

// this fails with the following error:
// java.nio.file.AccessDeniedException: /workspace
dir(workspaceDocker) {
sh 'pwd'
}
}
}
}


 

 

---
Originally reported by kvalev, imported from: dir('path') is broken when used within "docker.image().inside{}"


  • status: Open
  • priority: Blocker
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 2025-12-07

Raw content of original issue

It seems that when 'dir' is used within a docker container, it is expected that the directory exists on the host and not within the docker container. The following minimal Jenkinsfile showcases this issue:

 



node('docker') {

stage('Build within docker') {
// path to the workspace on the local machine and wthin the docker image
workspace = env.WORKSPACE
workspaceDocker = '/workspace'

image = docker.image("ubuntu:18.04")
image.pull()

image.inside("-v ${workspace}:${workspaceDocker}") {
sh 'pwd'

sh """#!/bin/sh
cd ${workspaceDocker}
pwd
"""

// this fails with the following error:
// java.nio.file.AccessDeniedException: /workspace
dir(workspaceDocker) {
sh 'pwd'
}
}
}
}



 

 

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.