I have installed Docker using apt in ubuntu
sudo apt install docker.io
And have installed JDK 17 as well as Jenkins.
So Whenever I try to build a docker image using Dockerfile through Jenkins which is in a different location than my build work space , it throws me an error stating
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/ubuntu/github_folder: permission denied
The Image gets build if I use the dockerfile from the same workspace i.e my GitHub folder which includes a Dockerfile.
I have tried to insert jenkins user in all the possible groups
sudo usermod -a -G docker jenkins
sudo usermod -a -G jenkins ubuntu
sudo usermod -a -G jenkins root
Still getting the same permission denied error.
I even checked with my dockerfile which is present in the location, and it defines "Dockerfile" with no extensions.
My pipeline :
pipeline {
agent any
stages {
stage("Checkout Code") {
steps {
cleanWs()
git branch: 'main', url: '<githublink>'
}
}
stage("Build Docker Image") {
steps {
script {
sh 'docker build -t uditdevadiiga/chatbot -f /var/lib/jenkins/workspace/<path>/Dockerfile .'
}
}
}
}
}