<p>I deployed Jenkins via Helm chart(<a href="https://github.com/jenkinsci/helm-charts/releases/tag/jenkins-3.11.4" rel="nofollow noreferrer">jenkins-helm:3.11.4</a>) on my local Kubernetes cluster(rancher desktop). I installed docker on <code>jenkins/inbound-agent</code> image because it is not included where I am using the default Jenkins-controller image as provided. When I run the docker command in the local pipeline I am getting a permission error as below.</p>
<p>I am aware that, the issue is the permission for /var/run/.docker.sock folder but I could not fix it and really stuck. I tried to add <code>command:[&quot;sh&quot;,&quot;-c&quot;,&quot;chmod 777 /var/run/.docker.sock ]</code> to the agent in values.yaml but this time jenkins did not up and running properly. I tried to add <code>RUN usermod -aG docker jenkins</code> to the Dockerfile but still same.</p>
<pre><code>jenkins@default-cnmq7:~/agent$ id
uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins),0(root)
jenkins@default-cnmq7:~/agent$ grep docker /etc/group
docker:x:107:
</code></pre>
<p>So how can I grant permission for this folder through the helm chart for Jenkins agent pod? Or what is the proper solution to fix this issue.</p>
<pre><code>node {
  stage('SCM') {
    checkout(scm)
  }
  stage('Build') {
    echo 'Building Project'
    sh &quot;&quot;&quot;
      docker pull alpine
    &quot;&quot;&quot;
  }
}

 [Pipeline] sh
    + docker pull alpine
    Using default tag: latest
    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post &quot;http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=alpine&amp;tag=latest&quot;: dial unix /var/run/docker.sock: connect: permission denied
</code></pre>
<p>values.yaml</p>
<pre><code>    controller:
      componentName: &quot;jenkins-controller&quot;
      image: &quot;jenkins&quot;
      # tag: &quot;2.319.3-jdk11&quot;
      tagLabel: jdk11
      imagePullPolicy: &quot;Always&quot;
      imagePullSecretName:
      javaOpts: &quot;-Xms512m -Xmx2048m&quot; 
      jenkinsUrl: &quot;http://localhost:8080&quot;
    agent:
      enabled: true
      defaultsProviderTemplate: &quot;&quot;
      # URL for connecting to the Jenkins contoller
      jenkinsUrl:
      jenkinsTunnel:
      image: &quot;jenkins/inbound-agent&quot;
      tag: &quot;4.11.2-5&quot;
      workingDir: &quot;/home/jenkins/agent&quot;
      nodeUsageMode: &quot;NORMAL&quot;
      componentName: &quot;jenkins-agent&quot;
      websocket: false
      privileged: true
      runAsUser: 
      runAsGroup:
      alwaysPullImage: true
      podRetention: &quot;Never&quot;
      volumes:
      - type: HostPath
        hostPath: /Users/username/workspace
        mountPath: /Users/username/workspace
      - type: HostPath
        hostPath: /var/run/docker.sock
        mountPath: /var/run/docker.sock
      command:
      args: &quot;${computer.jnlpmac} ${computer.name}&quot;
</code></pre>
<p>Dockerfile for jenkins agent</p>
<pre><code>FROM jenkins/inbound-agent:4.11.2-4
USER root
RUN set -eux &amp;&amp; \
    apt-get update &amp;&amp; \
    apt-get install -y curl sudo docker.io docker-compose &amp;&amp; \
    curl -sS https://raw.githubusercontent.com/HariSekhon/bash-tools/master/clean_caches.sh | sh
RUN usermod -aG docker jenkins
USER jenkins
</code></pre>

<p>First find the group id of docker from the Host</p>
<pre><code>$ grep docker /etc/group
docker:x:999:
</code></pre>
<p>Then create a user in the Dockerfile which its group is the same is docker group id.</p>
<pre><code>RUN groupadd -g 999 tech
RUN useradd -g tech tech
USER tech
</code></pre>
