Not able to Run Docker build on K8S : Permission denied

248 views Asked by At

I have installed bitnami/jenkins on my Managed Kubernetes cluster.

I need to run Jenkins job which will build docker image and push to docker repository. When I do this on a Jenkins instance in a simple container on host, I simply mount docker.sock as volume to the container.

But, when I try to do that in Jenkins on a Managed Kubernetes, I get permission denied error.

/bitnami/jenkins/home/tools/org.jenkinsci.plugins.docker.commons.tools.DockerTool/Docker/bin/docker login -u **** -p ******** 
https://mydocker-repo/ Warning: failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get 
http://%2Fvar%2Frun%2Fdocker.sock/v1.29/info: dial unix /var/run/docker.sock: connect: permission denied). Using system default: https://index.docker.io/v1/ Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post 
http://%2Fvar%2Frun%2Fdocker.sock/v1.29/auth: dial unix /var/run/docker.sock: connect: permission denied

Steps to reproduce the behaviour:

These are the helm values for the volume mount

extraVolumes:
  - hostPath:
      path: /var/run
    name: docker-sock
extraVolumeMounts:
   - mountPath: /var/run
     name: docker-sock

Expected behaviour:

Docker build should run properly I do not want to run the Jenkins POD as root especially, on Managed Kubernetes instance it is not allowed as well

How do I solve this error?

0

There are 0 answers