Answers: <p>You need to add the <code>jenkins</code> user to the <code>docker</code> group:</p>
  
  <pre><code># run the following command as root
  usermod -aG docker jenkins
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-20T13:11:54.597Z
Answers: as i mentioned i am running jenkins server itself on kubernetes cluster..which means i will have to ssh on the worker nodes to run that command on all the nodes...so not sure if this is a good practice..i mean point of jenkins is automation..running that command is very hacky and manual and looking for a better solution to that...except if that is `ONLY` solution or way around it which i highly doubt
Answers: uberrebu
Answers: CC BY-SA 4.0
Answers: 2020-01-20T14:14:04.350Z
Answers: Sorry, I read your question a bit too fast... So Jenkins is running in a container inside your Kubernetes cluster ? Could you add your `values.yaml` ?
Answers: Hedi Nasr
Answers: CC BY-SA 4.0
Answers: 2020-01-20T14:19:06.580Z
Answers: values.yaml is pretty much default with some additions..will update question with those additions
Answers: uberrebu
Answers: CC BY-SA 4.0
Answers: 2020-01-20T14:22:12.047Z
Answers: ok updated with what i added to values.yaml file
Answers: uberrebu
Answers: CC BY-SA 4.0
Answers: 2020-01-20T13:08:25.250Z
Answers: 2020-01-20T13:08:25.250Z
Answers: Hedi Nasr
Body: <p>I have jenkins deployed via helm charts on kubernetes cluster
  Now i want to be able to run helm to deploy helm charts applications on my kubernetes cluster and have the following in my jenkinsfile</p>
  
  <pre><code>pipeline {
      agent {
          docker { image 'alpine/helm' }
      }
      stages {
          stage('Deploy') {
              steps {
                  sh 'helm ls'
              }
          }
      }
  }
  </code></pre>
  
  <p>I also get kubernetes authentication setup on my jenkins so connection to cluster is fine but the error am getting now is the following</p>
  
  <pre><code>+ docker inspect -f . alpine/helm
  
  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.38/containers/alpine/helm/json: dial unix /var/run/docker.sock: connect: permission denied
  [Pipeline] isUnix
  [Pipeline] sh
  + docker pull alpine/helm
  Using default tag: latest
  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.38/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.38/images/create?fromImage=alpine%2Fhelm&amp;tag=latest: dial unix /var/run/docker.sock: connect: permission denied
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  ERROR: script returned exit code 1
  Finished: FAILURE
  </code></pre>
  
  <p>What am i missing and how to i get out of this error?</p>
  
  <p>Thanks</p>
  
  <p>UPDATE</p>
  
  <p>below are the additions/changes to default values.yaml file of the <code>stable/jenkins</code> helm chart</p>
  
  <pre><code>agent:
    enabled: true
    image: "joao29a/jnlp-slave-alpine-docker"
    tag: "latest"
    customJenkinsLabels: []
    # name of the secret to be used for image pulling
    imagePullSecretName:
    componentName: "jenkins-slave"
    #privileged: false
    privileged: true
  
    resources:
      requests:
        cpu: "512m"
        memory: "512Mi"
      limits:
        cpu: "512m"
        memory: "512Mi"
    # You may want to change this to true while testing a new image
    alwaysPullImage: false
    # Controls how agent pods are retained after the Jenkins build completes
    # Possible values: Always, Never, OnFailure
    podRetention: "Never"
    # You can define the volumes that you want to mount for this container
    # Allowed types are: ConfigMap, EmptyDir, HostPath, Nfs, Pod, Secret
    # Configure the attributes as they appear in the corresponding Java class for that type
    # https://github.com/jenkinsci/kubernetes-plugin/tree/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes
    # Pod-wide ennvironment, these vars are visible to any container in the agent pod
    envVars: []
    # - name: PATH
    #   value: /usr/local/bin
    volumes:
    # - type: Secret
    #   secretName: mysecret
    #   mountPath: /var/myapp/mysecret
     - type: HostPath
       hostpath: /var/run/docker.sock
       mountPath: /var/run/docker.sock
  </code></pre>
  
  <p>everything else pretty much same except for ingress hostnames and admin user password...above is most important modification to default values.yaml file</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-02-11T12:28:49.377Z
Comments: Did you able to resolve this issue? I am facing the same and run 'usermod -aG docker jenkins' did not worked for me
Comments: semural
Tags: <jenkins><kubernetes><jenkinsfile><helm>
Title: Getting permission denied with docker pipeline on jenkins
UserDisplayName: uberrebu
ThreadText: # Getting permission denied with docker pipeline on jenkins
  
  (Asked by: username_0 on 2020-01-20)
  
  I have jenkins deployed via helm charts on kubernetes cluster
  Now i want to be able to run helm to deploy helm charts applications on my kubernetes cluster and have the following in my jenkinsfile
  
  ```
  pipeline {
      agent {
          docker { image 'alpine/helm' }
      }
      stages {
          stage('Deploy') {
              steps {
                  sh 'helm ls'
              }
          }
      }
  }
  
  ```
  
  I also get kubernetes authentication setup on my jenkins so connection to cluster is fine but the error am getting now is the following
  
  ```
  + docker inspect -f . alpine/helm
  
  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.38/containers/alpine/helm/json: dial unix /var/run/docker.sock: connect: permission denied
  [Pipeline] isUnix
  [Pipeline] sh
  + docker pull alpine/helm
  Using default tag: latest
  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.38/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.38/images/create?fromImage=alpine%2Fhelm&tag=latest: dial unix /var/run/docker.sock: connect: permission denied
  [Pipeline] }
  [Pipeline] // withEnv
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  ERROR: script returned exit code 1
  Finished: FAILURE
  
  ```
  
  What am i missing and how to i get out of this error?
  
  Thanks
  
  UPDATE
  
  below are the additions/changes to default values.yaml file of the `stable/jenkins` helm chart
  
  ```
  agent:
    enabled: true
    image: "joao29a/jnlp-slave-alpine-docker"
    tag: "latest"
    customJenkinsLabels: []
    # name of the secret to be used for image pulling
    imagePullSecretName:
    componentName: "jenkins-slave"
    #privileged: false
    privileged: true
  
    resources:
      requests:
        cpu: "512m"
        memory: "512Mi"
      limits:
        cpu: "512m"
        memory: "512Mi"
    # You may want to change this to true while testing a new image
    alwaysPullImage: false
    # Controls how agent pods are retained after the Jenkins build completes
    # Possible values: Always, Never, OnFailure
    podRetention: "Never"
    # You can define the volumes that you want to mount for this container
    # Allowed types are: ConfigMap, EmptyDir, HostPath, Nfs, Pod, Secret
    # Configure the attributes as they appear in the corresponding Java class for that type
    # https://github.com/jenkinsci/kubernetes-plugin/tree/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes
    # Pod-wide ennvironment, these vars are visible to any container in the agent pod
    envVars: []
    # - name: PATH
    #   value: /usr/local/bin
    volumes:
    # - type: Secret
    #   secretName: mysecret
    #   mountPath: /var/myapp/mysecret
     - type: HostPath
       hostpath: /var/run/docker.sock
       mountPath: /var/run/docker.sock
  
  ```
  
  everything else pretty much same except for ingress hostnames and admin user password...above is most important modification to default values.yaml file
  
  **Tags:** jenkins, kubernetes, jenkinsfile, helm
  
  > **Comments:**
  > **username_1**: Did you able to resolve this issue? I am facing the same and run 'usermod -aG docker jenkins' did not worked for me  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-01-20. Score: 2
  
  You need to add the `jenkins` user to the `docker` group:
  
  ```
  # run the following command as root
  usermod -aG docker jenkins
  
  ```
  
  > **Comments:**
  > **username_0**: as i mentioned i am running jenkins server itself on kubernetes cluster..which means i will have to ssh on the worker nodes to run that command on all the nodes...so not sure if this is a good practice..i mean point of jenkins is automation..running that command is very hacky and manual and looking for a better solution to that...except if that is `ONLY` solution or way around it which i highly doubt  
  > **username_2**: Sorry, I read your question a bit too fast... So Jenkins is running in a container inside your Kubernetes cluster ? Could you add your `values.yaml` ?  
  > **username_0**: values.yaml is pretty much default with some additions..will update question with those additions  
  > **username_0**: ok updated with what i added to values.yaml file  
  
  ---
  
  