I am trying to load a tar ball using docker load in Jenkins pipeline. I am getting below error
+ docker load -i /home/test/build_artifacts/test.tar
open /home/test/build_artifacts/test.tar: permission denied
Here is my docker pipeline script
docker.withRegistry(registry, credentials) {
sh "docker load -i /home/test/build_artifacts/${repo_name}.tar"
docker.image(repo_name).push('latest')
}
I have already tried below and restarted my jenkins!
sudo usermod -a -G docker jenkins
and
sudo usermod -a -G docker root
Further docker load on terminal runs perfectly fine, so it must something related to jenkins
2
Answers
The solution lies in the fact that docker save always creates a tarball with restricted permissions, we need to do a
chmod 755
immediately after saving the file in the source machine then docker load in the destination works perfectly!When you use terminal, you are authenticated as your local user who probably has the necessary permissions. When you run a Jenkins pipeline, the pipeline runs as the
jenkins
user who is likely missing the necessary permissions. You either need to usechmod
to give the permissions, or have the artifacts get created and retrieved from within thejenkins
users’ home directory.