title: Jenkins pipeline unable to execute docker commands in pods
body: <p>I have Jenkins running in my GKE cluster and I am trying to deploy some code from my GitHub on the same cluster. I am trying to execute docker commands inside a pod with &quot;docker:19&quot; image. My pipeline configuration is inside the Jenkinsfile in my repository and I'm executing a &quot;Pipeline from SCM&quot; build. However, the console output of the build looks like several pods are being created and terminated constantly.</p>
  <p>Build logs</p>
  <pre><code>Started by user Aayush
  Obtained Jenkinsfile from git https://github.com/AayushPathak/fullstack-app-devops/
  Running in Durability level: MAX_SURVIVABILITY
  [Pipeline] Start of Pipeline
  [Pipeline] readTrusted
  Obtained buildPod.yaml from git https://github.com/AayushPathak/fullstack-app-devops/
  [Pipeline] podTemplate
  [Pipeline] {
  [Pipeline] node
  Created Pod: default/multi-crud-39-lx36n-8src2-xrqmf
  default/multi-crud-39-lx36n-8src2-xrqmf Container docker was terminated (Exit Code: 0, Reason: Completed)
  Still waiting to schedule task
  ‘Jenkins’ doesn’t have label ‘multi-crud_39-lx36n’
  Created Pod: default/multi-crud-39-lx36n-8src2-d8fr9
  default/multi-crud-39-lx36n-8src2-d8fr9 Container docker was terminated (Exit Code: 0, Reason: Completed)
  Created Pod: default/multi-crud-39-lx36n-8src2-rf4vw
  default/multi-crud-39-lx36n-8src2-rf4vw Container docker was terminated (Exit Code: 0, Reason: Completed)
  Created Pod: default/multi-crud-39-lx36n-8src2-ndh14
  default/multi-crud-39-lx36n-8src2-ndh14 Container docker was terminated (Exit Code: 0, Reason: Completed)
  Created Pod: default/multi-crud-39-lx36n-8src2-nbj0f
  default/multi-crud-39-lx36n-8src2-nbj0f Container docker was terminated (Exit Code: 0, Reason: Completed)
  .
  .
  .
  .
  </code></pre>
  <p>Here's how Jenkins is set up inside the cluster</p>
  <p>kubectl setup</p>
  <pre><code>aayush_pathak15@cloudshell:~/continuous-deployment-on-kubernetes/jenkins (multi-crud)$ kubectl get svc
  NAME                                            TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)                      AGE
  cd-jenkins                                      ClusterIP      10.3.248.115   &lt;none&gt;         8080/TCP                     2d22h
  cd-jenkins-agent                                ClusterIP      10.3.243.156   &lt;none&gt;         50000/TCP                    2d22h
  kubernetes                                      ClusterIP      10.3.240.1     &lt;none&gt;         443/TCP                      2d22h
  my-release-ingress-nginx-controller             LoadBalancer   10.3.241.83    34.122.66.93   80:31844/TCP,443:30350/TCP   2d4h
  my-release-ingress-nginx-controller-admission   ClusterIP      10.3.241.55    &lt;none&gt;         443/TCP                      2d4h
  </code></pre>
  <p>I believe I have set up the kubernetes cloud correctly</p>
  <p><a href="https://i.stack.imgur.com/9cy8b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9cy8b.png" alt="enter image description here" /></a></p>
  <p>Below are my Jenkinsfile and the Pod YAML inside which I want to execute my build</p>
  <p>Jenkinsfile</p>
  <pre><code>pipeline {
    environment {
      SHA = sh(returnStdout: true, script: &quot;git rev-parse HEAD&quot;)
    }
    agent {
      kubernetes {
        idleMinutes 5
        yamlFile 'buildPod.yaml'
      }
    }
    stages {
      stage('test') {
        steps {
          container('docker') {
            sh 'docker build -t aayushpathak/frontend-test -f ./client/Dockerfile.dev ./client'
            sh 'docker run aayushpathak/frontend-test -e CI=true npm test'
          }
        }
      }
  
      stage('build-push-production-images') {
        steps {
          container('docker') {
            sh 'docker build -t aayushpathak/frontend-test -f ./client/Dockerfile.dev ./client'
            sh 'docker run aayushpathak/frontend-test -e CI=true npm test'
          }
        }
      }
  
      stage('deploy') {
        environment {
          GC_HOME = '$HOME/google-cloud-sdk/bin'
          GC_KEY = credentials('jenkins-secret')
        }
  
        steps {
          container('docker') {
            sh(&quot;rm -r -f /root/google-cloud-sdk&quot;)
            sh(&quot;curl https://sdk.cloud.google.com | bash &gt; /dev/null;&quot;)
            sh(&quot;${GC_HOME}/gcloud components update kubectl&quot;)
            sh(&quot;${GC_HOME}/gcloud auth activate-service-account --key-file=${GC_KEY}&quot;)
            sh(&quot;${GC_HOME}/kubectl apply -f k8s&quot;)
            sh(&quot;${GC_HOME}/kubectl set image deployments/server-deployment server=aayushpathak/fullstack-server:${SHA}&quot;)
            sh(&quot;${GC_HOME}/kubectl set image deployments/client-deployment client=aayushpathak/fullstack-client:${SHA}&quot;)
          }
        }
      }
    }
  }
  </code></pre>
  <p>buildPod.yaml</p>
  <pre><code>apiVersion: v1
  kind: Pod
  spec:
    containers:
      - name: docker
        image: docker:19
        imagePullPolicy: Always
        volumeMounts:
          - name: docker
            mountPath: /var/run/docker.sock
    volumes:
      - name: docker
        hostPath:
          path: /var/run/docker.sock
  </code></pre>