Search code examples
dockerjenkinsjenkins-pipeline

Jenkins docker load permission denied


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


Solution

  • 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!