'Running docker within docker missing file - docker run -v /var/jenkins_home/job:/build ./script.sh

I have Jenkins running in docker container. In Jenkins container we also run docker commands from pipelines. The problem with it is that when we run this from pipeline:

docker run -v /var/jenkins_home/job:/build ./script.sh 

It does not mount the content of /var/jenkins_home/job

So I tested it with:

docker run -v /tmp:/build ./script.sh 

And it mounted /tmp of the host machine not of Jenkins docker.

What causes this behaviour and how can I mount the path of Jenkins docker not host machine? OR is there anyway to make docker interpret /var/jenkins_home/job to host folder automatically?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source